@Query("SELECT new com.cmict.iot.server.common.data.DeviceTransferInfo(d.id,d.tenantId,d.deviceId,d.authorizationCode,d.deviceProfileId" + ",d.newTenantId,d.newTenantName,d.createdTime,d.transferState,d.notes,d.transferId,d.deviceName,d.deviceProfileName)" + " FROM DeviceTransferEntity d WHERE " + "d.newTenantId = :newTenantId " + "AND LOWER(d.deviceName) LIKE LOWER(CONCAT('%',:device_name, '%')) ") Page<DeviceTransferInfo> ReceiveDeviceTransferInfosByTenantId(@Param("newTenantId") UUID tenantId,@Param("device_name") String deviceName, Pageable pageable);模糊条件是deviceName,目前sql报错,怎么修改
时间: 2024-01-11 10:03:15 浏览: 148
你可以尝试修改 SQL 查询语句中的 `LOWER(d.deviceName)` 为 `LOWER(d.deviceName)`,即将 `LOWER()` 函数应用于查询参数 `deviceName` 而不是数据库列 `deviceName`。修改后的 SQL 查询语句如下所示:
```java
@Query("SELECT new com.cmict.iot.server.common.data.DeviceTransferInfo(d.id, d.tenantId, d.deviceId, d.authorizationCode, d.deviceProfileId, d.newTenantId, d.newTenantName, d.createdTime, d.transferState, d.notes, d.transferId, d.deviceName, d.deviceProfileName) " +
"FROM DeviceTransferEntity d " +
"WHERE d.newTenantId = :newTenantId " +
"AND LOWER(d.deviceName) LIKE LOWER(CONCAT('%', :deviceName, '%')) ")
Page<DeviceTransferInfo> ReceiveDeviceTransferInfosByTenantId(@Param("newTenantId") UUID tenantId, @Param("deviceName") String deviceName, Pageable pageable);
```
这样,查询参数 `deviceName` 将会被转换为小写,并且可以与数据库列 `deviceName` 进行匹配,从而实现模糊查询。
阅读全文