gpt4 book ai didi

java - 我可以在接口(interface)扩展 CrudRepository 中定义哪些方法列表

转载 作者:行者123 更新时间:2023-12-01 09:14:00 25 4
gpt4 key购买 nike

每个使用 Spring Data JPA 的示例都包含此方法:

   public interface PersonRepository extends CrudRepository<Person, Long> {

List<Person> findByLastName(@Param("name") String name);

}

是否有其他方法可以 JPA+Hibernate 在运行时实现然后 findByVarialbleName 我可以在存储库中定义它?

最佳答案

请引用query method document
一些示例查询方法:

public interface PersonRepository extends Repository<User, Long> {

List<Person> findByEmailAddressAndLastname(EmailAddress emailAddress, String lastname);

// Enables the distinct flag for the query
List<Person> findDistinctPeopleByLastnameOrFirstname(String lastname, String firstname);
List<Person> findPeopleDistinctByLastnameOrFirstname(String lastname, String firstname);

// Enabling ignoring case for an individual property
List<Person> findByLastnameIgnoreCase(String lastname);
// Enabling ignoring case for all suitable properties
List<Person> findByLastnameAndFirstnameAllIgnoreCase(String lastname, String firstname);

// Enabling static ORDER BY for a query
List<Person> findByLastnameOrderByFirstnameAsc(String lastname);
List<Person> findByLastnameOrderByFirstnameDesc(String lastname);
}

Spring Data JPA 还支持 deleteBycount

关于java - 我可以在接口(interface)扩展 CrudRepository 中定义哪些方法列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40711376/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com