有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java querydsl spring数据jpa运算符优先级

public interface ItemRepository extends JpaRepository<Item, Integer> {
   List<Item> findByNameAndDescriptionIsNullOrDescription(String name, String desc); 
 }

在本机查询中,findByNameAndDescriptionIsNullOrDescriptionwhere条件被转换为

where item0_.NAME=? and (item0_.DESC is null) or item0_.DESC=? 

我需要where item0_.NAME=? and (item0_.DESC is null or item0_.DESC=?)

我正在使用下面的

  • spring-data-commons-1.6.3。释放罐子

  • spring-data-jpa-1.4.3。释放罐子

  • (i)hibernate-entitymanager-4.2.14。SP1-redhat-1。jar,(ii)hibernate-jpa-2.0-api-1.0.1。最后的红帽2号。JBOSS EAP 6.3提供的jar


共 (2) 个答案

  1. # 1 楼答案

    需要添加第二个参数说明什么。。只需在下面使用:

    列出findByNameAndDescription(字符串名称、字符串描述)

    即使你传递desc参数null,你也会得到想要的结果

  2. # 2 楼答案

    也许你做不到

    Spring Data querydsl仅用于简单的SQL查询,如果需要更复杂的内容,请使用@Query注释

    其他开发人员也更容易理解您使用的查询,而不是分析您的方法名