[SPRING] JPA 쿼리메소드 요약

2022. 4. 19. 22:38·SPRING
728x90

JPA 쿼리메소드 요약

키워드 예제 JPQL 
Distinct findDistinctByLastnameAndFirstname select distinct …​ where x.lastname = ?1 and x.firstname = ?2
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, Null findByAge(Is)Null … 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> ages) … where x.age not in ?1
True findByActiveTrue() … where x.active = true
False findByActiveFalse() … where x.active = false
IgnoreCase findByFirstnameIgnoreCase … where UPPER(x.firstname) = UPPER(?1)
  • 조건절의 값이 두개 초과인 경우, 다른방법으로 해결하자 (메소드명이 너무김)

참고

  • https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#reference
저작자표시

'SPRING' 카테고리의 다른 글

[SPRING] JPA 영속성 전이  (0) 2022.06.06
[SPRING] WEBFLUX 리액티브 오퍼레이션 정리  (0) 2022.05.08
[SPRING] Bean 생명주기 콜백 (PostConstruct / PreDestory)  (0) 2022.03.02
[SPRING] Transaction Propagation  (0) 2021.09.22
[SPRING] AOP  (0) 2021.07.31
'SPRING' 카테고리의 다른 글
  • [SPRING] JPA 영속성 전이
  • [SPRING] WEBFLUX 리액티브 오퍼레이션 정리
  • [SPRING] Bean 생명주기 콜백 (PostConstruct / PreDestory)
  • [SPRING] Transaction Propagation
집한구석
집한구석
  • 집한구석
    tgyun615.info
  • 전체
    오늘
    어제
    • 카테고리 (183)
      • JAVA (38)
      • SPRING (15)
      • KOTLIN (23)
      • NETTY (1)
      • DEVOPS (3)
      • DOCKER (7)
      • KUBERNETES (2)
      • JAVASCRIPT (1)
      • SPLUNK (3)
      • ELK (7)
      • KAFKA (2)
      • GO (4)
      • ALGORITHM & DATA STRUCTURE (9)
      • IDE (5)
      • OS (16)
      • NETWORK (14)
      • GCP (2)
      • AWS (2)
      • DATABASE (10)
      • CLEANCODE (7)
      • OTHER (12)
  • 최근 글

  • 태그

    AWS
    자바
    이펙티브코틀린
    SQL
    splunk
    엘라스틱서치
    docker
    프로그래머스
    JPA
    클린코드
    IntelliJ
    Spring
    이펙티브 코틀린
    코틀린
    go
    Kafka
    ElasticSearch
    Elk
    cleancode
    java
  • 링크

    • github
    • linkedin
    • resume
  • hELLO· Designed By 정상우. v4.10.3
집한구석
[SPRING] JPA 쿼리메소드 요약
상단으로

티스토리툴바