-
[JPA]Hibernate 사용Spring-diary/WEB 2020. 3. 1. 20:52
Pom.xml
Context 파일
테이블 및 Entity 설정
- @Entity,@Table Annotation으로 설정
- JPA를 사용해서 테이블과 매핑할 클래스는 @Entity Annotation을 필수로 붙여야 한다.
*@Entity 적용시 주의 사항
-Parameter 없는public 또는 protected의 기본 생성자가 필수다.
-final 클래스,enum,interface,inner 클래스에는 사용이 불가능하다.
-저장할 필드에 final 사용 불가
- @Table은 엔티티와 매핑할 테이블을 지정한다. 생략하면 매핑한 엔티티 이름을 테이블 이름으로 사용한다.
- @ID는 Entity의 PK를 주는 Annotation이다.
- @Column은 열을 지정해준다.
JpaRepository 설정
- Entity의 기본적인 CRUD가 가능하도록 Interface를 상속받는다.
DB 사용할 Service 설정
View,Controller
- View와 Controller는 기존 Spring 로직과 동일하게 작성한다.
'Spring-diary > WEB' 카테고리의 다른 글
시험 (0) 2020.03.20 Spring Security+MyBatis로 Spring 게시판 만들기 3 (0) 2020.03.01 Spring rootContext와 ServletContext (0) 2020.03.01 Spring Security+MyBatis로 Spring 게시판 만들기 2 (0) 2020.03.01 Spring Security+MyBatis로 Spring 게시판 만들기 1 (0) 2020.03.01