mybatis xml踩坑记录
问题1
当传递参数为时间类型时不要使用字符串判空否则就会报以下错误
错误示范
//注意以下时错误写法
<if test="begTime != null and endTime != null and begTime != '' and endTime != ''">
AND insert_time BETWEEN #{begTime,jdbcType=TIMESTAMP} AND #{endTime,jdbcType=TIMESTAMP}
</if>
Caused by: java.lang.IllegalArgumentException: invalid comparison: cn.hutool.core.date.DateTime and java.lang.String
正确写法
//注意以下时错误写法,不要判断空字符串
<if test="begTime != null and endTime != null">
AND insert_time BETWEEN #{begTime,jdbcType=TIMESTAMP} AND #{endTime,jdbcType=TIMESTAMP}
</if>
问题2
当使用in查询数据时,不能直接传字符串比如1,2,否则虽不会报错,但查出数据是有问题的
错误示范
//Dao层
public class CuuService(){
public Integer getOne(String ids);
}
//调用方法
public class cuuApplication(){
CuuService

本文分享了在使用MyBatisXML时遇到的两个常见问题:1.时间类型参数的正确判断方式,避免因为空字符串引发的异常;2.如何正确处理IN查询中的数组参数,包括使用@Param注解和避免null值。
最低0.47元/天 解锁文章
5913

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



