我需要创建一个能够执行的查询,即使你在它的参数中发送一个空值,params是默认格式的ISO-8601,查询工作没有任何参数,但是如果我发送参数它会停止工作。有什么建议?
CODE:
@Query(value = "SELECT re "
+ "FROM report re "
+ "WHERE ( "
+ "( re.date BETWEEN :dateFrom AND :dateTo) OR (:dateFrom IS NULL OR :dateTo IS NULL))"
List<Report> reportByDate(@Param("dateFrom") Instant dateFrom,
@Param("dateTo") Instant dateTo)
错误:
异常[EclipseLink-4002](Eclipse Persistence Services - 2.6.4.v20160829-44060b6):org.eclipse.persistence.exceptions.DatabaseException 内部异常:org.h2.jdbc.JdbcSQLException: SQL语句“SELECT DISTINCT T1.COL_1,T1.COL_2,T1.COL_3”中的语法错误 来自报告T1 在哪里((T0.DATE BETWEEN TS'2000-03-07 17:01:01.0'AND TS'2030-03-07 17:01:01.0')或((2030-03-08T01 [*]:01:01Z) IS NULL)AND(2000-03-08T01:01:01Z IS NULL)))“; 预期“[,::,*,/,%,+, - ,||,〜,!〜,NOT,LIKE,ILIKE,REGEXP,IS,IN,BETWEEN,AND,OR,,,)”; SQL语句: