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
- 원형그래프
- Oracle
- jsp연결
- Cisco
- ciscopacket
- 정처기필기
- ospf
- php
- javaee
- 라우터
- 네트워크관리사
- 데이터베이스
- cisco packet
- html
- autoset
- 버추얼머신
- 네트워크
- 이것이 자바다
- 참조타입
- VLAN
- sql
- jsp
- Java
- 오라클
- rinux
- NCS
- 리눅스
- 자바
- w3school
- 정보처리기사
Archives
- Today
- Total
기록해! 정리해!
JPAJarTymeleaf-1 검색하기 ( 동적 DSL 사용하기 ) 본문
1.pom.xml
dependecy에 추가
<!-- querydsl Setting 추가(1) -->
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
</dependency>
<!-- querydsl Setting 추가(2) -->
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-apt</artifactId>
</dependency>
build에 추가
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- 동적 DSL을 위한 plugin 추가 -->
<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>apt-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
<configuration>
<outputDirectory>src/main/querydsl</outputDirectory>
<processor>com.querydsl.apt.jpa.JPAAnnotationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
+ Maven Update
>> 설정완료.
2. BoardRepository (책 257p)
findBoardBy Title Containing
= 메소드(엔터티는 생략가능) 변수 Like문
3. BoardService
: getBoardList 괄호안에 vo 받아줫음
4. BoardServiceImpl
: getBoardList 괄호안에 vo 받아줫음
package com.rubypaper.board;
import java.util.List;
import java.util.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class BoardServiceImpl implements BoardService{
@Autowired
private BoardRepository boardRepo;
@Override
public void insert(Board vo) {
boardRepo.save(vo);
}
@Override
public List<Board> getBoardList(Board vo) {
return (List<Board>)boardRepo.findAll();
}
@Override
public Optional<Board> getBoard(Long seq) {
return boardRepo.findById(seq);
}
@Override
public void delete(Long seq) {
boardRepo.deleteById(seq);
}
@Override
public void update(Board vo) {
boardRepo.save(vo);
}
@Override
public List<Board> getfindByTitle(Board vo) {
return boardRepo.findByTitleContaining(vo.getSearchKeyword());
}
@Override
public List<Board> getfindByWriter(Board vo) {
return boardRepo.findByWriterContaining(vo.getSearchKeyword());
}
}
5. BoardController
@RequestMapping("/getBoardList.do")
public void getBoardList(Model model, Board vo) {
if (vo.getSearchCondition() == null || vo.getSearchKeyword() == null || vo.getSearchKeyword().equals("") ) {
model.addAttribute("li", boardService.getBoardList(vo));
} else if(vo.getSearchCondition().equals("title")) {
model.addAttribute("li", boardService.getfindByTitle(vo));
} else if (vo.getSearchCondition().equals("writer")) {
model.addAttribute("li", boardService.getfindByWriter(vo));
}
}
6. getBoardList
<form action="getBoardList.do">
<select name=searchCondition>
<option value="title"> 제목 </option>
<option value="writer"> 작성자 </option>
</select>
<input type=text name=searchKeyword>
<input type=submit value="검색하기">
</form>
>>
>100
> 앙
'SpringBoot' 카테고리의 다른 글
JPAJarThymeleaf-2 (Test) (0) | 2022.10.19 |
---|---|
JPAJarThymeleaf-2 (Board, QLogin) (0) | 2022.10.19 |
JPAJarTymeleaf-1 상세보기, 삭제하기, 수정하기 (0) | 2022.10.18 |
JPAJarTymeleaf-1 UI (getBoardList, form) (0) | 2022.10.18 |
JPAJarTymeleaf-1 Test(Crudrepository 메소드사용) (0) | 2022.10.18 |
Comments