出现原因:时间范围查询导致的文字与格式字符串不匹配
错误sql:
<if test="xyDateQd1 != null and !xyDateQd1.equals('')">
and
A.XY_DATE_QD >= #{xyDateQd1} <!-- 协议签订日期 -->
</if>
<if test="xyDateQd2 != null and !xyDateQd2.equals('')">
and
A.XY_DATE_QD <= #{xyDateQd2} <!-- 协议签订日期 -->
</if>
解决方法:
这个错误一般出现在时间字段上,即你插入的时间格式和数据库现有的时间格式不一致,解决的方法是格式化你
插入的时间: 使用To_Date()函数,具体使用方法可以看这个链接https://blog.csdn.net/idomyway/article/details/78785112。
所以我在mybaits中进行了To_Date()。
修改后:
<if test="xyDateQd1 != null and !xyDateQd1.equals('')">
and
A.XY_DATE_QD >= to_date(#{xyDateQd1},'yyyy-mm-dd ')<!-- 协议签订日期 -->
</if>
<if test="xyDateQd2 != null and !xyDateQd2.equals('')">
and
A.XY_DATE_QD <= to_date(#{xyDateQd2},'yyyy-mm-dd ')<!-- 协议签订日期 -->
</if>