很多表单查询都会按照时间区间查询,这个时候前端是固定传入长度为2的时间数组参数。后端如果分成2个参数去接受,就显得很麻烦,直接用数组接受会方便很多,但是有坑。
一、在做时间区间查询的时候,前端固定传一个长度为2的时间数组参数。
二、后端实体类中,用这样的形式接收。
三、如果像这样直接按照索引获取,会报错
-
<if test="checkTimeArray != null and checkTimeArray.length == 2">
-
AND DATE_FORMAT(a.check_time,'%Y-%m-%d') BETWEEN DATE_FORMAT(#{checkTimeArray[0]},'%Y-%m-%d') AND DATE_FORMAT(#{checkTimeArray[1]},'%Y-%m-%d')
-
</if>
-
### Error querying database. Cause: java.lang.IllegalStateException: Type handler was
null on parameter mapping
for property
'checkTimeArray[0]'. It was either not specified and/
or could not be found for the javaType ([Ljava.util.Date;) : jdbcType (null) combination.
-
### Cause: java.lang.IllegalStateException: Type handler was null on parameter mapping for property 'checkTimeArray[0]'. It was either not specified and/or could not be found for the javaType ([Ljava.util.Date;) : jdbcType (null) combination.
四、只需要在参数后面加上javaType和jdbcType就好了。如
#{checkTimeArray[0],javaType=java.util.Date,jdbcType=TIMESTAMP}
-
<if test="checkTimeArray != null and checkTimeArray.length == 2">
-
AND DATE_FORMAT(a.check_time,'%Y-%m-%d') BETWEEN DATE_FORMAT(#{checkTimeArray[0],javaType=java.util.Date,jdbcType=TIMESTAMP},'%Y-%m-%d') AND DATE_FORMAT(#{checkTimeArray[1],javaType=java.util.Date,jdbcType=TIMESTAMP},'%Y-%m-%d')
-
</if>
转载:https://blog.csdn.net/qq_39648029/article/details/108594806
查看评论