항해99/TIL | WIL

2023.02.13 (36일)

태감새 2023. 2. 14. 02:28

Day 36


1. JPA 메서드

지금까지 Repository에 필요시 선언하는 메서드가 어떻게 나오는 건지 몰랐는데 오늘 매니점님한체 질문해서 그개 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)

2. JPA 강의

오늘 강의를 들으면서 가장 인상에 남은 것은 프록시 객체다. 프록시 객체를 사용해서 호출했다고 바로 DB에서 데이터를 읽어오는 것이 아닌 최초 실행시 불러오는 방식으로 프록시라는 껍데기만 있는 객체를 만드는 것이다. 이렇게 호출 하는 것이 지연 로딩데 실무에서 자주 사용한다고 한다. 그 외 내용이 더 많지만 너무 붙여넣기 하는거 같아서 이정도로 하겠다.  

3. 주특기 심화 과제 lv. 2 

기능 구현은 다 완성했고 모르는 부분을 공부해보려고 했는데 시간이 없어서 못했다. 내일 오전에 lv. 3을 도전해보고 시간이 남으면 찾아봐야겠다. 

'항해99 > TIL | WIL' 카테고리의 다른 글

2023.02.15 (38일)  (0) 2023.02.16
2023.02.14 (37일)  (0) 2023.02.15
2023.02.12 (35일)  (0) 2023.02.13
WIL (4주)  (0) 2023.02.12
2023.02.11 (34일)  (0) 2023.02.12