-
[JPA]Hibernate 사용Spring-diary/WEB 2020. 3. 1. 20:52
Pom.xml
hibernate와 jpa 의존성 주입 Context 파일
기본 설정 DB 설정 resolver 설정 hibernateJpaVendorAdapter bean 생성 hibernate entityManger 설정 및 경로 설정 테이블 및 Entity 설정
- @Entity,@Table Annotation으로 설정
- JPA를 사용해서 테이블과 매핑할 클래스는 @Entity Annotation을 필수로 붙여야 한다.
*@Entity 적용시 주의 사항
-Parameter 없는public 또는 protected의 기본 생성자가 필수다.
-final 클래스,enum,interface,inner 클래스에는 사용이 불가능하다.
-저장할 필드에 final 사용 불가
- @Table은 엔티티와 매핑할 테이블을 지정한다. 생략하면 매핑한 엔티티 이름을 테이블 이름으로 사용한다.
- @ID는 Entity의 PK를 주는 Annotation이다.
- @Column은 열을 지정해준다.
파일 이름 테이블명,Entity설정,column설정,pk설정 테이블 열의 setter,getter 설정 JpaRepository 설정
- Entity의 기본적인 CRUD가 가능하도록 Interface를 상속받는다.
JpaRepository DB 사용할 Service 설정
사용할 db를 가지고 온다. insert문 jparepository에 내장된 method를 사용한다. View,Controller
- View와 Controller는 기존 Spring 로직과 동일하게 작성한다.
tomcat을 실행하게 되면 자동으로 테이블이 생성된다. '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