很多表單查詢都會按照時間區間查詢,這個時候前端是固定傳入長度為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://www.uj5u.com/qita/67917.html
標籤:其他
上一篇:CGB2005-京淘17

