- JpaRepository
- 다중 필터링
- 주의 사항
(1) Spring Data JPA에서 제공하는 인터페이스
(2) 인터페이스에 따로 @Repository등의 어노테이션을 추가할 필요가 없다.
JpaRepository를 상속받을 때는 사용될 Entity 클래스와 ID값이 들어가게 된다.
public interface ItemRepository extends JpaRepository<Item, Long>
(1) save()
(2) findOne()
(3) findAll()
(4) count()
(5) delete()
규칙에 맞는 메서드를 작성해야 한다.
(1) findBy로 시작 => 쿼리를 요청하는 메서드
(2) countBy로 시작 => 쿼리 결과 레코드 수를 요청하는 메서드
(3) 실제 사용
List<Item> findByDateBetween(LocalDate start, LocalDate end); // start 시간부터 end시간까지
List<Item> findByPriceBetween(Long min, Long max); // min 가격부터 max 가격까지
List<Item> findByDateBetweenAndPriceBetween(LocalDate start, LocalDate end, Long min, Long max);
List<Item> findByDateBetweenOrPriceBetween(LocalDate start, LocalDate end, Long min, Long max);
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE)
등의 방식을 추가해야지 시간으로 입력이 받아짐.