mybatis ﹤! [Cdata []]> Use
Description:
<sql>
<!--
WARNING - @mbggenerated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Thu Oct 10 09:46:29 CST 2013.
-->
<if test="page != null">
<![CDATA[ limit #{page.begin}, #{page.length} ) as temp_page_table) ]]>
<if test="orderByClause != null">
order by ${orderByClause}
</if>
</if>
</sql>
The above code is the automatic code generated by the Generator of MyBatis, why add ﹤! [CDATA []]>? It feels completely unnecessary. The SQL statement inside does not destroy the XML document structure, or causes SQL errors? why?
=============================================================
Added instructions, I know its usage, I just don’t understand the paging of SQL
limit #{page.begin}, #{page.length} ) as temp_page_table)
This statement, why add <! [Cdata []]>?
Solution 1:
W3C XML CDATA
cdata has nothing to do with mybatis.
The term CDATA refers to the text data (Unparsed Character Data) that should not be parsed by the XML parser. All the contents of the CDATA part are ignored by parsers.
As for your XML, even if there is no error, it has added CDATA, the landlord also said that it is the code that automatically generated through the generator. Since the automatic generation tool is naturally not as smart, it is only used in the most common way. This is nothing.
Solution 2:
Theoretically, this Limit does not need to add this. The Limit paging I use is never needed, but you still test it. After removing it, you will report an error. Prevent “<” such symbols in Mybatis Not recognize
Solution 3:
You have no SQL, it should be a unified CDATA to prevent your SQL from appearing in XML illegal characters such as “<” and “&”
Solution 4:
In XML elements, “<” and “&” are illegal.
“<” will cause errors because the parser will interpret the character as the beginning of the new element.
“&” will also cause errors, because parsers will interpret the character as the beginning of the character entity.
Some texts, such as JavaScript code, contain a large number of “<” or “&” characters. To avoid errors, the script code can be defined as CDATA.
CDATA section will be ignored by parsers.
Suppose there is such a SQL
SELECT * FROM users WHERE registerAt > 100
If you do not use CDATA packaging, XML parser goes back to analyze, and it will encounter “>” to cause the document structure errors
The above introduces the answer to the use of “MYBATIS! [CDATA []]> Use, I hope it will be helpful to netizens in need.
This article Links: http://www.codes51.com/itwd/3339853.htm