Detailed Explanation of Mybatis Special Character Processing
- 2021-08-31 09:27:59
- OfStack
Foreword:
Mybatis special character processing, Mybatis xml file special character processing, here provides solutions and examples, you can refer to the following:
1. Problem description:
When querying, you need to obtain the data in the time interval, as follows:
<if test="startTime != null" >
and l.CREATE_TIME >= #{startTime}
</if>
<if test="endTime != null" >
and l.CREATE_TIME < #{endTime}
</if>
However, in the xml file in Mybatis, the query cannot use the less than sign (
<
), because this belongs to the opening tag and is a special character
2. Solutions
In the query, special characters can be avoided by including them with CDATA. This method applies to all special characters.
<![CDATA[
]]>
Examples are as follows:
<if test="startTime != null" >
<![CDATA[
and l.CREATE_TIME >= #{startTime}
]]>
</if>
<if test="endTime != null" >
<![CDATA[
and l.CREATE_TIME < #{endTime}
]]>
</if>
MyBatis returns the primary key, and MyBatis Insert operation returns the primary key:
Thank you for reading, hope to help everyone, thank you for your support to this site!