매일매일 10분 시간을 맞춰놓고 뭐라도 써보는 카테고리입니다.
항상 시간이 부족해서 시작도 못하는 나 자신을 발견하고,
'아무말스토리' 에서 (내 개인 블로그도 아니니..) 실험적으로 10분 안에 글쓰기를
도전해 볼까 합니다.
카테고리의 절대 규칙은, 글 쓰다가 10분 되는 순간 '맞춤법' 검사만 하고 그냥 그 상태로 발행해버리는 거예요.
짤 찾는데... 3분이 넘어 버렸네요...
사실 첫 글로 스프링 Data JPA에서 복잡한 쿼리를 손쉽게? 만들 수 있는 Specifications에 대해 써볼까 합니다.
공식 출처: https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#specifications
Spring Data JPA - Reference Documentation
Example 119. Using @Transactional at query methods @Transactional(readOnly = true) interface UserRepository extends JpaRepository { List findByLastname(String lastname); @Modifying @Transactional @Query("delete from User u where u.active = false") void del
docs.spring.io
위 페이지에서 코드를 가져와 보면, 요렇게 생겼습니다.
public class CustomerSpecs {
public static Specification<Customer> isLongTermCustomer() {
return (root, query, builder) -> {
LocalDate date = LocalDate.now().minusYears(2);
return builder.lessThan(root.get(Customer_.createdAt), date);
};
}
}
2 년 이전에 생성된 고객(=Customer)을....
'10분끄적임' 카테고리의 다른 글
JPA Specifications 가볍게 살펴보기 (0) | 2022.12.12 |
---|---|
php preg_replace 함수 (6) | 2022.11.30 |