我需要使用JpaRepository执行类似的操作:
select * from table where ( propertyTwo like '%something%' or propertyThree like '%something%' or propertyFour like '%something%' ) and propertyOne in (a,b);
我目前这样做:
findByPropertyOneInAndPropertyTwoContainingOrPropertyThreeContainingOrPropertyFourContaining(List param1, String param2, String param3, String param4)
但是方法做的是这样的:
select * from table where propertyTwo like '%something%' or propertyThree like '%something%' or propertyFour like '%something%' and propertyOne in (a,b);
这与上面的第一个sql查询不同。
如何才能获得正确的结果?
答案 0 :(得分:0)
像Slava Said一样,你应该这样做:
@Query("from table t where t.propertyOne in :param1 and (t.propertyTwo like :param2 or t.propertyThree like :param3 or t.propertyFour like :param4)")
List<Table> findByParams(@Param("param1") List<String> param1, @Param("param2") String param2, @Param("param3") String param3, @Param("param4") String param4);