본문 바로가기
spring/JPA

JPARepository

by coie 2021. 5. 21.

JpaRepository vs CrudRepoistory

 

crud의 경우 정말 기본적인 

create , read , update , delete의 기능들을 지원 한다.

JPARepository는 JPA에 특화된 것으로

Crud기능에서 페이징,정렬 등의 기능을 지원한다.

 

그리고 JPARepository에서 지원하는 기본적인 crud는

method 기능
save() insert, update
 findOne() 기본키로 한 개의 정보를 찾음
findAll() 전체 (list)
 count() 갯수
 delete() 삭제

와 같이 되어 있다.

그런데 만약

본인이 필요로 하는 기능이 없다? 하면

새로 선언을 해주면 되는데 이 경우 규칙을 지켜서 선언해준다.

method 기능
 findBy로 시작 where 절을 추가해서 쿼리문 작성
 countBy로 시작 갯수를 알려달라는 쿼리문

 

이 이외는 아래의 사이트에서 매번 참고해야 할 것 같다..

 

http://docs.spring.io/spring-data/jpa/docs/1.10.1.RELEASE/reference/html/#jpa.sample-app.finders.strategies

 

Spring Data JPA - Reference Documentation

Example 11. Repository definitions using Domain Classes with mixed Annotations interface JpaPersonRepository extends Repository { … } interface MongoDBPersonRepository extends Repository { … } @Entity @Document public class Person { … } This example

docs.spring.io

 

'spring > JPA' 카테고리의 다른 글

Jpa로 게시물(1)  (0) 2021.05.25
JPA/Dto?Entity?  (0) 2021.05.22
JPAEntity  (0) 2021.05.21