JpaRepository 대표 query를 알아보자.
public interface ProductRepository extends JpaRepository<Product, Long> {
// (1) 회원 ID 로 등록된 상품들 조회
List<Product> findAllByUserId(Long userId);
// (2) 상품명이 title 인 관심상품 1개 조회
Product findByTitle(String title);
// (3) 상품명에 word 가 포함된 모든 상품들 조회
List<Product> findAllByTitleContaining(String word);
// (4) 최저가가 fromPrice ~ toPrice 인 모든 상품들을 조회
List<Product> findAllByLpriceBetween(int fromPrice, int toPrice);
// (5) createdAt을 기준으로 내림차순 조회
List<Post> findAllByOrderByCreatedAtDesc();
// existsBy, findAllByAandB 도 가능
}
https://joojimin.tistory.com/56
JpaRepository Query 작성
본 내용은 Spring Data JPA 2.5.2 버전 기준으로 작성되었습니다 https://docs.spring.io/spring-data/jpa/docs/2.5.2/reference/html/#jpa.repositories Spring Data JPA - Reference Documentation Example 109...
joojimin.tistory.com
https://dazbee.tistory.com/49?category=1040314
[SpringBoot] JPA를 이용해 랜덤한 하나의 레코드만 가져오려면 어떻게 해야할까?
랜덤 레코드 가져오기 고민이 많았던 부분이다. 미니프로젝트 진행 중 테이블 전체 중 하나의 랜덤 column만 가져와야하는 요구사항이 있어서 어떻게 가져와야할지 생각을 많이 했다. 요구사항은
dazbee.tistory.com
https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods
Spring Data JPA - Reference Documentation
Example 109. 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
infinite scroll 설명