有一个具有列A和列B的实体,使用方法的JpaRepository可以很好地工作:
@Repository
public interface Repo extends JpaRepository<Entity, UUID> {
List<Entity> findAllByAAndB(String a, String b);
}但是,我还需要获取b相等且a为空的所有行。
List<Entity> findAllByAAndBOrAIsNullAndB(String a, String b);发布于 2019-08-04 15:17:49
在这种情况下,不需要第二种方法,第一种方法工作得很好:
Repo.findAllByAAndB(null, SerachedValueForB)根据所找到的值,我们传递任何相应的参数。
Repo.findAllByAAndB("0", SerachedValueForB)
Repo.findAllByAAndB(SerachedValueForA, SerachedValueForB)在本质上,搜索方法的签名是相同的(返回和传递参数),但这是错误的。
List<Entity> findAllByAAndB(String a, String b);
List<Entity> findAllByAAndBOrAIsNullAndB(String a, String b);虽然方法的名称不同,但其目的和本质是相同的。
另一个特殊情况是,如果您需要,例如,选择一个参数的最大值,在这种情况下,您需要一个特殊的方法。
https://stackoverflow.com/questions/57336318
复制相似问题