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
반응형
'Spring' 카테고리의 다른 글
[Spring] Springboot와 Redis 연동 (0) | 2023.03.28 |
---|---|
[Spring] Querydsl Error 해결 (0) | 2020.03.17 |
[Spring] Querydsl 적용하기 (0) | 2020.03.16 |
[Spring] JPA로 update 작업하기 (0) | 2020.03.13 |
[Spring] Page<?> 객체에 있는 page 정보들 다루기 (0) | 2020.03.13 |