Difference between findBy and findOneBy in Spring data JPA

后端 未结 3 805
半阙折子戏
半阙折子戏 2020-12-28 15:43

All i know so far is that FindBy can return multiple results while FindOneBy will return a single result or null when we use it the following way.

List

        
3条回答
  •  我在风中等你
    2020-12-28 16:31

    I have done some tests and Spring Data ignore all characters between the method (find, delete,...) and By.

    In https://github.com/spring-projects/spring-data-commons/blob/14d5747f68737bb44441dc511cf16393d9d85dc8/src/main/java/org/springframework/data/repository/query/parser/PartTree.java#L65 it is the \p{Lu}.*? part.

    Spring Data only use return type to decide how handle responses.

    So it is possible to define these following methods even if it is not correct semantically.

    Department findAllByDepartmentId(Long Id);
    List findOneByDepartmentName(String name);
    

提交回复
热议问题