When using MyBatis, our SQL is written in the XML mapping file, if there are some special characters in the SQL written, it will be escaped when parsing the XML file, but we do not want him to be escaped, so we have to use <! [cdata[]]> to solve.
<! [Cdata[]]> is what, this is the XML syntax. All content inside CDATA is ignored by the parser.
If the text contains a lot of "<" characters <= and "&" characters--like program code, it's best to put them all in a CDATA widget.
But there's a problem, that's <if test=. > </if> <where> </where> <choose> </choose> <trim> </trim> and so on these tags will not be parsed, so we only put the statements with special characters in the <! [cdata[]]> as narrow as possible <! [Range of cdata[]]>.
Examples are as follows:
[Java]View plain copy < param name= "allowfullscreen" value= "false" >< param name= "wmode" value= "Transparent" > print?
- <select id= "Alluserinfo" Parametertype= "Java.util.HashMap" resultmap= "UserInfo1" >
- <![ cdata[
- select newsedit,newsid, newstitle from Shoppingguide where 1=1 and newsday > #{starttime} and newsday <= #{endtime}
- ]]>
- <if test = "etidname!=" ">&NBSP;&NBSP;
- and newsedit =#{etidname}
- </IF>&NBSP;&NBSP;
- </select>
Because there are ">" "<=" special characters, so use <! [cdata[]]> to comment, but there are <if> tags, so put <if> wait outside
CDATA in the MyBatis