Java Spring数据JPA NativeQuery类搜索
我尝试了以下查询:Java Spring数据JPA NativeQuery类搜索,java,spring,orm,spring-data-jpa,Java,Spring,Orm,Spring Data Jpa,我尝试了以下查询: @Query(value = "SELECT distinct `id`,`customer name`,`customer number` FROM My_Data WHERE `customer number` like '%" + ":customerNumber" + "%'", nativeQuery = true) public List<MyData> findDistinctByCustomerNumberContainingIgn
@Query(value = "SELECT distinct `id`,`customer name`,`customer number` FROM My_Data WHERE `customer number` like '%"
+ ":customerNumber" + "%'", nativeQuery = true)
public List<MyData> findDistinctByCustomerNumberContainingIgnoreCase(
@Param("customerNumber") String customerNumber);
@Query(value=“从My_数据中选择不同的'id','customer name','customer number','customer number',其中'customer number'类似“%”
+“:customerNumber“+”%”,nativeQuery=true)
公共列表由CustomerNumber ContainingIgnoreCase查找目标(
@参数(“customerNumber”)字符串customerNumber);
当我运行这个时,
我得到:
java.lang.IllegalArgumentException:具有该位置的参数[1]
不存在异常
由于我的表有一些限制,我需要一个本机查询。您已将占位符放在括号内,引擎将其视为普通字符串 如果仅使用%将其包围,则引擎将知道如何在已解析查询中添加parentherse:
@Query(value = "SELECT distinct `id`,`customer name`,`customer number` FROM My_Data
WHERE `customer number` like %:customerNumber%", nativeQuery = true)
展示方法signature@MaciejKowalski现在用方法签名更新了问题。