今天写代码遇到的,检查了一下发现实际上是把null值作为参数了
遇到此类问题,需要检查传入的参数中是否有空值(null).
查询代码如下:
@Repository public interface OssDao extends JpaRepository<OssFileEntity, Long> { @Query(nativeQuery = true, value = " SELECT " + " "uri" " + " FROM " + " "oss_file" " + " WHERE " + " "namespace" = :namespace " + " AND "prefix" LIKE COALESCE (:prefix, '%%') " + " AND "name" LIKE COALESCE (:fileName, '%%') " ) List<String> findUriByCondition(@Param("namespace") String namespace, @Param("prefix") String prefix, @Param("fileName") String fileName);
}
为了做Oracle和MySQL兼容, 也是绞尽乳汁了