기록해! 정리해!

JPAJarThymeleaf-2 (Member) 본문

SpringBoot

JPAJarThymeleaf-2 (Member)

zsuling 2022. 10. 19. 17:25

1. Member

package com.rubypaper.board;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import lombok.Data;

@Data
@Entity
@Table(name="Member1019")
public class Member {

	@Id
	@GeneratedValue
	private  Long seq;  // number(19,0) 정수 19자리 
	
	@Column(unique=true) // 유일키 제약조건
	private  String  writer;
	
	private  int age;
	
	
}

2. MemberRepository

package com.rubypaper.board;

import org.springframework.data.repository.CrudRepository;

public interface MemberRepository 
         extends CrudRepository <Member,Long>{

}

3. MemberTest

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.Member;
import com.rubypaper.board.MemberRepository;

@RunWith(SpringRunner.class)
@SpringBootTest
public class MemberTest {
	    
		@Autowired
		private MemberRepository memberRepo;
		
	    @Test 
	 	public void insert() {
			
			for(int i=1; i<=3; i++) {
			Member member = new Member();
			
			member.setWriter("닭강정"+i);
	        member.setAge(17);

		    memberRepo.save(member);
			}
		}
}

>>

 

'SpringBoot' 카테고리의 다른 글

JPAJarThymeleaf-2 (동적DSL)  (0) 2022.10.20
JPAJarThymeleaf-2 (Junit 연습문제)  (0) 2022.10.19
JPAJarThymeleaf-2 (Pageable, JPQL,네이티브쿼리)  (0) 2022.10.19
JPAJarThymeleaf-2 (Test)  (0) 2022.10.19
JPAJarThymeleaf-2 (Board, QLogin)  (0) 2022.10.19
Comments