Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- 이것이 자바다
- jsp연결
- 오라클
- 자바
- Oracle
- Cisco
- 참조타입
- php
- sql
- 네트워크
- html
- Java
- 네트워크관리사
- rinux
- 정보처리기사
- 리눅스
- 버추얼머신
- w3school
- NCS
- jsp
- autoset
- 원형그래프
- 데이터베이스
- javaee
- 라우터
- 정처기필기
- VLAN
- ospf
- ciscopacket
- cisco packet
Archives
- Today
- Total
기록해! 정리해!
JPAJarThymeleaf-2 (동적DSL) 본문
1. DynamicBoardRepository
:QuerydslPredicateExecutor
package com.rubypaper.board;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.repository.CrudRepository;
public interface DynamicBoardRepository
extends CrudRepository <Board, Long>,
QuerydslPredicateExecutor<Board>{
}
2. DynamicQueryTest
package com.rubypaper.test;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.test.context.junit4.SpringRunner;
import com.querydsl.core.BooleanBuilder;
import com.rubypaper.board.Board;
import com.rubypaper.board.DynamicBoardRepository;
import com.rubypaper.board.QBoard;
@RunWith(SpringRunner.class)
@SpringBootTest
public class DynamicQueryTest {
@Autowired
private DynamicBoardRepository boardRepo;
@Test
public void testDynamicQuery() {
String searchCondition = "TITLE";
String searchKeyword = "J";
BooleanBuilder builder = new BooleanBuilder();
QBoard qboard = QBoard.board;
if(searchCondition.equals("TITLE")) {
builder.and(qboard.title.like("%"+ searchKeyword + "%"));
}else if(searchCondition.equals("CONTENT")) {
builder.and(qboard.content.like("%"+ searchKeyword + "%"));
}
Pageable paging = PageRequest.of(0, 5);
Page<Board> boardList= boardRepo.findAll(builder, paging);
for(Board m:boardList) {
System.out.println("==>" + m.toString());
}
}
}
>>
: 기존에는 BoardRepository 에 계속 메소드를 추가해서 사용했는데
동적DSL은 DynamicBoardRepository에 추가를 하지않아도 됐음
'SpringBoot' 카테고리의 다른 글
JPAJarThymeleaf-2 (양방향 연관관계 매핑) (0) | 2022.10.20 |
---|---|
JPAJarThymeleaf-2 (단방향 연관관계 매핑) (0) | 2022.10.20 |
JPAJarThymeleaf-2 (Junit 연습문제) (0) | 2022.10.19 |
JPAJarThymeleaf-2 (Member) (0) | 2022.10.19 |
JPAJarThymeleaf-2 (Pageable, JPQL,네이티브쿼리) (0) | 2022.10.19 |
Comments