https://www.tutorialspoint.com/hibernate/hibernate_mapping_types.htm
https://zetawiki.com/wiki/JPA_DB%EC%9E%90%EB%A3%8C%ED%98%95_%EB%A7%A4%ED%95%91
springboot는 pom - initializer - test - main
순으로 돌아간다
프로젝트,에디터에서 DB로 테이블 만들기
데이터 베이스에 접근할수 있는 Repository만들기
Role은 만들어서 사용할 예정임
범용적으로 접근할수 있도록 Common에 Entity만들기
여기서 만들 Entity를 db에서 Table로 사용할 예정
만든 Entity에 접근 할수 있도록 dependency추가하기
common.xml 부분 복사해서
ShoweWebParent.xml에 추가하기
메이븐 업데이트 하면 BackEnd.Repository에서 임포트 가능
DB와 연결 잘 되었는지 테스트하고, DB에 테이블 만들기 위해서 Test코드 작성하기
ShopeeBackEnd src/test/java
replace의 경우 자동으로 import되지 않으면 수동으로 입력하기
package com.shope.admin.user;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.test.annotation.Rollback;
import com.shope.common.entity.Role;
@DataJpaTest
//데이터 베이스의 데이터가 더 우세 하니 바꾸지 말아라
@AutoConfigureTestDatabase(replace = Replace.NONE)
@Rollback(false) //에디터에서 데이터베이스로 데이터 넣기가 가능해짐
public class RoleRepositoryTests {
@Autowired
private RoleRepository repo;
//JUnit test
@Test
public void testCreateFirstRole() {
Role roleAdmin = new Role("Admin", "manage everything");
Role savedRole = repo.save(roleAdmin);
//아이디가 하나라도 있는지 확인해 달라
assertThat(savedRole.getId()).isGreaterThan(0);
}
}
컨트롤러에 어노테이션 추가하기
데이터 베이스 데이터 지우기