Mybatis parameter is an object, the object contains Date[] array, how to get the value according to the index

Many form queries will be queried according to the time interval. At this time, the front end is a fixed time array parameter with a length of 2. If the backend is divided into two parameters to accept, it is very troublesome. It is much more convenient to accept directly with an array, but there are pits.

1. When doing time interval query, the front end will always pass a time array parameter of length 2.

2. In the back-end entity class, use this form to receive.

3. If you get directly according to the index like this, an error will be reported

 <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.

Four, just add javaType and jdbcType after the parameters. Such as

#{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>

 

Guess you like

Origin blog.csdn.net/qq_39648029/article/details/108594806
Recommended