gpt4 book ai didi

java - Spring Data JPA/Boot : findBy . .. 或

转载 作者:行者123 更新时间:2023-11-30 08:32:40 25 4
gpt4 key购买 nike

我想在我的存储库中编写一个 finder 方法来根据一个字段或另一个字段查找对象,同时提供一个参数,例如:

@RepositoryDefinition(domainClass = Person.class, idClass = Long.class)
public interface PersonRepository extends CrudRepository<Person, Long> {

List<Person> findAllByIdOrAnotherId(someId);
}

如何在不使用 SQL 的情况下做到这一点?

最佳答案

我向该方法添加了第二个参数,它起作用了。

List<Transaction> findAllByIdOrParentId(Long id, Long parentId);

这只是方法的定义,因为我将相同的参数从服务传递给方法:

List<Transaction> transactions = transactionRepository.findAllByIdOrParentId(transactionId, transactionId);

关于java - Spring Data JPA/Boot : findBy . .. 或,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40023995/

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