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
- 자바
- 데이터베이스
- sql
- php
- Java
- 이것이 자바다
- Oracle
- jsp연결
- autoset
- 오라클
- jsp
- 네트워크관리사
- 원형그래프
- ciscopacket
- w3school
- 정처기필기
- Cisco
- 네트워크
- javaee
- html
- 정보처리기사
- ospf
- NCS
- rinux
- 라우터
- 리눅스
- VLAN
- 참조타입
- cisco packet
- 버추얼머신
Archives
- Today
- Total
기록해! 정리해!
JPAJarThymeleaf-2 (Test) 본문
책 260p
1. BoardTest에 값 넣기 insert
: BoardTest Junit으로 실행시킴
package com.rubypaper.test;
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.test.context.junit4.SpringRunner;
import com.rubypaper.board.Board;
import com.rubypaper.board.BoardRepository;
@RunWith(SpringRunner.class)
@SpringBootTest
public class BoardTest {
@Autowired
private BoardRepository boardRepo;
@Test
public void test() {
for(int i=1; i<=5; i++) {
Board board = new Board();
board.setTitle("JPA 공부하기"+i);
board.setWriter("닭강정"+i);
board.setContent("JPA 열심히 공부합시다."+i);
board.setPassword("1234");
boardRepo.save(board);
}
}
}
2. select
@Test // ( selectAll )
public void testSelectAll() {
List<Board> li = (List<Board>)boardRepo.findAll();
for(Board m :li ) {
System.out.println(m.toString());
}
}
3.selectOne (값 하나만 찾기)
@Test // ( selectOne )
public void testSelectOne() {
// Optional 이란? Null Point Exception 을 방지해준다.
Optional<Board> m = boardRepo.findById(3L);
System.out.println(m.toString());
}
+ 제목에 JPA가 들어있는 레코드만 출력해보시오
1) BoardRepository에 코드추가
List<Board> findByTitleContaining(String searchkeyword);
2) BoardTest
@Test
public void selectTitleLike() {
String str = "JPA";
List<Board> li = boardRepo.findByTitleContaining(str);
for(Board m:li) {
System.out.println("==>" + m.toString());
}
}
+ 보기와 같은 제목을 찾아보시오
1) BoardRepository에 코드추가
2) BoardTest
@Test
public void selectTest() {
// 정해진 레코드 여러개 찾을 수 있다
Optional<Board> m1 =boardRepo.findById(9L);
System.out.println("==>" + m1.toString());
List<Board> li2 =boardRepo.findBoardByTitle("JAVA 공부하기1");
for(Board m2:li2) {
System.out.println("==>" + m2.toString());
}
String title = "JAVA 공부하기1";
String writer = "밀크티1";
List<Board> li3 = boardRepo.findBoardByTitleAndWriter(title, writer);
for(Board m3:li3) {
System.out.println("==>" + m3.toString());
}
}
>>
4. @Before
: @Test전에 먼저 실행됨
: 조회하기 전에 값 추가하기
@Before //@Test 실행 전에 먼저 실행됨
public void test() {
for(int i=1; i<=4; i++) {
Board board = new Board();
board.setTitle("RPA 공부하기"+i);
board.setWriter("우롱티"+i);
board.setContent("RPA 열심히 공부합시다."+i);
board.setPassword("7878");
boardRepo.save(board);
}
}
@Test // ( selectAll )
public void testSelectAll() {
List<Board> li = (List<Board>)boardRepo.findAll();
for(Board m :li ) {
System.out.println(m.toString());
}
}
5. SeqBetween
1) BoardRepository에 코드추가
List<Board> findByTitle(String str);
List<Board> findBySeqBetween(Long k1, Long k2);
2) BoardTest
@Test
public void selectTest() {
List<Board> li =boardRepo.findBySeqBetween(3L, 7L);
for(Board m : li) {
System.out.println(m);
}
}
>>
6. SeqLessThan
1) BoardRepository
List<Board> findBySeqLessThan(Long k1);
2) BoardTest
@Test
public void selectLessThan() {
List<Board> li =boardRepo.findBySeqLessThan(5L);
for(Board m : li) {
System.out.println(m);
}
}
7. null값 넣기
1) BoardTest
@Test
public void test() {
for(int i=1; i<=7; i++) {
Board board = new Board();
board.setTitle("공부하기"+i);
board.setWriter("공차"+i);
board.setContent("열심히 공부합시다."+i);
board.setPassword("");
boardRepo.save(board);
}
}
>>오라클
8. is null
1) BoardRepository
List<Board> findByPasswordIsNull();
2) BoardTest
@Test
public void selectLessThan() {
List<Board> li =boardRepo.findByPasswordIsNull();
for(Board m : li) {
System.out.println(m);
}
}
>>
9. Like /Containing 차이
1) BoardRepository
List<Board> findByTitleLike(String str);
List<Board> findByTitleContaining(String str);
2) BoardTest
@Test
public void selectLike() {
String str="%S%";
List<Board> li =boardRepo.findByTitleLike(str);
for(Board m : li) {
System.out.println(m);
}
String str1="S";
List<Board> li1 =boardRepo.findByTitleContaining(str1);
for(Board m1 : li1) {
System.out.println(m1);
}
}
>>
10. 정렬
1) BoardRepository
List<Board> findByTitleContainingOrderBySeqDesc(String str);
2) BoardTest
@Test
public void selectLike() {
String str="Spring";
List<Board> li =boardRepo.findByTitleContainingOrderBySeqDesc(str);
for(Board m : li) {
System.out.println(m);
}
}
>>
+
1) BoardRepository
List<Board> findByTitleContainingOrderBySeqDesc(String str);
List<Board> findByOrderBySeqDesc();
2) BoardTest
@Test
public void selectLike() {
String str="Spring";
List<Board> li =boardRepo.findByTitleContainingOrderBySeqDesc(str);
for(Board m : li) {
System.out.println(m);
}
List<Board> li1 =boardRepo.findByOrderBySeqDesc();
for(Board m1 : li1) {
System.out.println(m1);
}
}
11. Or 연산
List<Board> findByTitleContainingOrWriterContaining(String str1, String str2);
@Test
public void selectLike() {
String str="Spring";
List<Board> li =boardRepo.findByTitleContainingOrderBySeqDesc(str);
for(Board m : li) {
System.out.println(m);
}
List<Board> li1 =boardRepo.findByTitleContainingOrWriterContaining("J", "6");
for(Board m1 : li1) {
System.out.println(m1);
}
}
>>
'SpringBoot' 카테고리의 다른 글
JPAJarThymeleaf-2 (Member) (0) | 2022.10.19 |
---|---|
JPAJarThymeleaf-2 (Pageable, JPQL,네이티브쿼리) (0) | 2022.10.19 |
JPAJarThymeleaf-2 (Board, QLogin) (0) | 2022.10.19 |
JPAJarTymeleaf-1 검색하기 ( 동적 DSL 사용하기 ) (0) | 2022.10.18 |
JPAJarTymeleaf-1 상세보기, 삭제하기, 수정하기 (0) | 2022.10.18 |
Comments