오답노트

[Spring JPA] Query Method 본문

Java/Spring

[Spring JPA] Query Method

권멋져 2023. 7. 19. 15:10

Query Method

JPA에서 쿼리문을 직접 작성하지 않고 Method명으로 지정만 하면 자동으로 쿼리를 만들고 요청까지 해주는 편리한 기능이 있다.

 

https://www.javaguides.net/2018/11/spring-data-jpa-query-creation-from-method-names.html

 

Spring Data JPA - Query Creation from Method Names

In this article, we will learn how we can create query methods by using the query generation from the method name strategy. Spring Data JPA offers various ways to create a query. In this article, we will focus on how to generate a query using method name s

www.javaguides.net

 

public interface UserRepository extends JpaRepository<User, Long> {
    List<User> findByName(String name);

    User findByEmail(String email);

    User getByEmail(String email);

    User readByEmail(String email);

    User queryByEmail(String email);

    User searchByEmail(String email);

    User streamByEmail(String email);

    User findUserByEmail(String email);

    List<User> findByEmailAndName(String email, String name);

    List<User> findByIdAfter(Long id);

    List<User> findByAddressListIsNotEmpty();

    List<User> findByNameIn(List<String> names);

    List<User> findTop1ByName(String name);

    List<User> findTopByNameOrderByIdDesc(String name);

    Page<User> findByName(String Name, Pageable pageable);


}

'Java > Spring' 카테고리의 다른 글

[Spring JPA] 영속성 전이(Cascade) 와 고아제거속성(orphanRemoval)  (0) 2023.07.24
[Spring JPA] Entity Relations  (0) 2023.07.19
[Spring JPA] Auditing  (0) 2023.07.19
[Spring JPA] H2 In-Memory DB  (0) 2023.07.18
[Spring] 코드 Test하기  (0) 2023.07.17