Spring

[Spring] Querydsl DynamicQuery

quedevel 2020. 3. 17. 13:35
728x90
반응형

BoardRepositoryImpl.java

    @Override
    public List<Board> findDynamicQuery(String title, String writer, String content) {
        return queryFactory
                .selectFrom(board)
                .where( BooleanExpressionUtils.containsTitle(title),
                        BooleanExpressionUtils.containsWriter(writer), 
                        BooleanExpressionUtils.containsContent(content))
                .fetch();
    }

 

BooleanExpressionUtils.java

public final class BooleanExpressionUtils {

    public static BooleanExpression containsTitle(String title){
        return StringUtils.isEmpty(title)? null: board.title.contains(title); 
    }
    public static BooleanExpression containsWriter(String writer){
        return StringUtils.isEmpty(writer)? null: board.writer.contains(writer); 
    }
    public static BooleanExpression containsContent(String content){
        return StringUtils.isEmpty(content)? null: board.content.contains(content); 
    }
}

 

728x90
반응형