1.用小于或小于等于的场景
代码1:
<delete id="delOvertimeLog" parameterType="java.lang.Integer">
delete from operate_log where operate_time < curdate() - interval #{logCleanTime} day
</delete>
现象:会报解析异常
Caused by: org.apache.ibatis.builder.BuilderException: Error creating document instance. Cause: org.xml.sax.SAXParseException; lineNumber: 10; columnNumber: 53; 元素内容必须由格式正确的字符数据或标记组成。
at org.apache.ibatis.parsing.XPathParser.createDocument(XPathParser.java:259) ~[mybatis-3.4.4.jar:3.4.4]
at org.apache.ibatis.parsing.XPathParser.<init>(XPathParser.java:125) ~[mybatis-3.4.4.jar:3.4.4]
at org.apache.ibatis.builder.xml.XMLMapperBuilder.<init>(XMLMapperBuilder.java:78) ~[mybatis-3.4.4.jar:3.4.4]
at org.mybatis.spring.SqlSessionFactoryBean.buildSqlSessionFactory(SqlSessionFactoryBean.java:520) ~[mybatis-spring-1.3.1.jar:1.3.1]
... 54 common frames omitted
解决方式:
<delete id="delOvertimeLog" parameterType="java.lang.Integer">
delete from operate_log where operate_time < curdate() - interval #{logCleanTime} day
</delete>
代码2:
<delete id="delOvertimeLog" parameterType="java.lang.Integer">
delete from operate_log where operate_time > curdate() - interval #{logCleanTime} day
</delete>
现象:正常执行,没有错误
总结:如果用小于号(<) 或者(<=)就必须转义,其余可以不转义,因为Mapper.xml 文件里 < (小于)号 , >(大于)号 ,会被认为是括号。
附上: