所以我的问题如下:
我有一张表我想要一个过滤器来应用。此过滤器应调用查询,该查询根据给定信息查找报告。
这是我查询的外观:
@Query("SELECT r FROM Report r WHERE r.importanceLevel = COALESCE(importance,'%')" +
"AND r.source = COALESCE(source,'%')" +
"AND r.resolvedStatus = COALESCE(resolvedStatus,'%')" +
"AND r.header LIKE + '%' COALESCE(query,'%') + '%'")
List<Report> getReportsByAppliedFilter(@Param("importance") int importance, @Param("source") String source,
@Param("resolvedStatus") int resolvedStatus, @Param("query") String query);
问题是:IntelliJ不喜欢以下内容:
LIKE + '%' COALESCE(query,'%') + '%'
错误:预期,得到+
你知道如何解决这个问题吗?
答案 0 :(得分:1)
@Query(value = "SELECT r FROM Report r WHERE r.importanceLevel = COALESCE(importance,'%')" +
"AND r.source = COALESCE(source,'%')" +
"AND r.resolvedStatus = COALESCE(resolvedStatus,'%')" +
"AND r.header LIKE CONCAT('%', COALESCE(query,'%'), '%')")
答案 1 :(得分:0)
如果您的列名是request_status
,表名是connections
,则使用 COALESCE ,如
@Query(value = "SELECT connections.id, COALESCE(connections.request_status,'') as request_status.... ", nativeQuery = true)
List<ZXYType> xysfunction();
如果request_status
为null,则将其替换为空字符串。