一、方法一:cdate: cdate可以保留原始的特殊符号,如换行、比较符号等等
List<MetaServer> selectByCreateTime(@Param("startDay") Date startDay, @Param("endDay") Date endDay);
mapper.xml:
<select id="selectByCreateTime" resultMap="BaseResultMap">
SELECT
<include refid="Base_Column_List" />
FROM
meta_server
WHERE
<if test="startDay != null">
<![CDATA[
create_time >= #{startDay,jdbcType=TIMESTAMP}
]]>
</if>
<if test="endDay != null">
<![CDATA[
AND create_time <= #{endDay,jdbcType=TIMESTAMP}
]]>
</if>
AND
is_delete = 0
</select>
注意,if条件里面和null做比较就可以了,不要和''做比较,否则会报错java.lang.String不可以和java.util.Date做比较。
二、使用>和<等来替换大于小于号
本文介绍了一种在MyBatis中使用cdate保留特殊符号的方法,并详细解释了如何通过mapper.xml文件中的if条件判断,实现对MetaServer表中createTime字段的日期范围查询。文章强调了在与null进行比较时的注意事项,避免了字符串与日期类型不匹配的错误。
mybatis比较时间&spm=1001.2101.3001.5002&articleId=83792414&d=1&t=3&u=e5d0d72508c442dea390fe19cc3c4520)
1367

被折叠的 条评论
为什么被折叠?



