https://docs.spring.io/spring-data/jpa/docs/1.10.1.RELEASE/reference/html/#jpa.sample-app.finders.strategies
JpaRepository를 단순하게 상속하는 것만으로
Entity 하나에 대해서 아래와 같은 기능을 제공하게 된다.
method | 기능 |
---|---|
save() | 레코드 저장 (insert, update) |
findOne() | primary key로 레코드 한건 찾기 |
findAll() | 전체 레코드 불러오기. 정렬(sort), 페이징(pageable) 가능 |
count() | 레코드 갯수 |
delete() | 레코드 삭제 |
메서드 이름 키워드 | 샘플 | 설명 |
---|---|---|
And | findByEmailAndUserId(String email, String userId) | 여러필드를 and 로 검색 |
Or | findByEmailOrUserId(String email, String userId) | 여러필드를 or 로 검색 |
Between | findByCreatedAtBetween(Date fromDate, Date toDate) | 필드의 두 값 사이에 있는 항목 검색 |
LessThan | findByAgeGraterThanEqual(int age) | 작은 항목 검색 |
GreaterThanEqual | findByAgeGraterThanEqual(int age) | 크거나 같은 항목 검색 |
Like | findByNameLike(String name) | like 검색 |
IsNull | findByJobIsNull() | null 인 항목 검색 |
In | findByJob(String … jobs) | 여러 값중에 하나인 항목 검색 |
OrderBy | findByEmailOrderByNameAsc(String email) | 검색 결과를 정렬하여 전달 |
Keyword | Sample | JPQL snippet |
---|---|---|
And |
findByLastnameAndFirstname |
… where x.lastname = ?1 and x.firstname = ?2 |
Or |
findByLastnameOrFirstname |
… where x.lastname = ?1 or x.firstname = ?2 |
Is,Equals |
findByFirstname ,findByFirstnameIs ,findByFirstnameEquals |
… where x.firstname = ?1 |
Between |
findByStartDateBetween |
… where x.startDate between ?1 and ?2 |
LessThan |
findByAgeLessThan |
… where x.age < ?1 |
LessThanEqual |
findByAgeLessThanEqual |
… where x.age ⇐ ?1 |
GreaterThan |
findByAgeGreaterThan |
… where x.age > ?1 |
GreaterThanEqual |
findByAgeGreaterThanEqual |
… where x.age >= ?1 |
After |
findByStartDateAfter |
… where x.startDate > ?1 |
Before |
findByStartDateBefore |
… where x.startDate < ?1 |
IsNull |
findByAgeIsNull |
… where x.age is null |
IsNotNull,NotNull |
findByAge(Is)NotNull |
… where x.age not null |
Like |
findByFirstnameLike |
… where x.firstname like ?1 |
NotLike |
findByFirstnameNotLike |
… where x.firstname not like ?1 |
StartingWith |
findByFirstnameStartingWith |
… where x.firstname like ?1 (parameter bound with appended % ) |
EndingWith |
findByFirstnameEndingWith |
… where x.firstname like ?1 (parameter bound with prepended % ) |
Containing |
findByFirstnameContaining |
… where x.firstname like ?1 (parameter bound wrapped in % ) |
OrderBy |
findByAgeOrderByLastnameDesc |
… where x.age = ?1 order by x.lastname desc |
Not |
findByLastnameNot |
… where x.lastname <> ?1 |
In |
findByAgeIn(Collection<Age> ages) |
… where x.age in ?1 |
NotIn |
findByAgeNotIn(Collection<Age> age) |
… where x.age not in ?1 |
True |
findByActiveTrue() |
… where x.active = true |
False |
findByActiveFalse() |
… where x.active = false |
IgnoreCase |
findByFirstnameIgnoreCase |
… where UPPER(x.firstame) = UPPER(?1) |