Because the design date format is different from the various data types in the database, the VARCHAR type is selected to store the date, which corresponds to the Java String type. Therefore, the SQL statement used in the Mapper.xml file can be used.date_format (field name, “Date Format”), this is the method of MySQL database. hereWhat needs to be noted is that “less than” should be used “& lt;” at the time of the comparison date
<if test="params.taskName != null">
and task_name like '%${params.taskName}%'
<if test="params.keyWord != null">
or task_name like '%${params.keyWord}%'
or task_describe like '%${params.keyWord}%'
</if>
</if>
<if test="params.publishTime1 != null">
and DATE_FORMAT(publish_time,'%Y-%m-%d %H:%i') >= DATE_FORMAT(#{params.publishTime1},'%Y-%m-%d %H:%i')
</if>
<if test="params.publishTime2 != null">
and DATE_FORMAT(publish_time,'%Y-%m-%d %H:%i') <= DATE_FORMAT(#{params.publishTime2},'%Y-%m-%d %H:%i')
</if>
<if test="params.endTime1 != null">
and DATE_FORMAT(end_time,'%Y-%m-%d %H:%i') >= DATE_FORMAT(#{params.endTime1},'%Y-%m-%d %H:%i')
</if>
<if test="params.endTime2 != null">
and DATE_FORMAT(end_time,'%Y-%m-%d %H:%i') <= DATE_FORMAT(#{params.endTime2},'%Y-%m-%d %H:%i')
</if>
<if test="params.keyWord != null and params.taskName == null">
and task_name like '%${params.keyWord}%'
or task_describe like '%${params.keyWord}%'
</if>
By the way, record a question:
KEYWORD is not a field in the database. When the parameter is valuable, the query target is task_name and task_describe. Here you need to pay attention to use or use or OR.