Ibatis as a semi-automatic or mapping tool, its flexibility is increasingly manifested and more and more people are inclined to use it in projects. Because characters that conflict with the XML specification often have an impact on the legality of XML mapping files in SQL. Many people are aware of the use of <! [cdata[]]> tags to avoid collisions, but there are some details that need special attention when there are dynamic statements in the SQL configuration.) When using Ibatis, you often need to configure the SQL statements to be executed. Friends who have used Ibatis know that the inevitable will encounter some incompatible, conflicting characters, most people also know that the use of <! The [cdata[]]> tag avoids the effect of characters in SQL that conflict with XML specifications on the legality of XML mapping files. However, if dynamic statements are used in Ibatis, there are some details to be noted. Here's an example: Environment: Oracle, Ibatis, java error Example 1: the symbol "<=" will affect the legality of the XML map file
<select id= "Find" parameterclass= "Java.util.Map" resultclass= "Java.lang.Long" >
<![ cdata[
Select id
from TableA A,
TableB b
<dynamic prepend= "WHERE" >
<isnotnull prepend= " and "property=" StartDate ">
a.act_time >= #startDate # and A.act_time <=
#endDate # and
a.id = b.id< c9/></isnotnull>
</dynamic>
]]>
</select>
Error Example 2: Use the entire SQL statement with <! [cdata[]]> tag to avoid conflicts is generally feasible, but because of the dynamic statement (where part) in the SQL configuration, the system will not recognize the dynamic judgment part, causing the entire SQL statement to be illegal.
<select id= "Find" parameterclass= "Java.util.Map" resultclass= "Java.lang.Long" >
select IDs from
TableA a ,
TableB b
<dynamic prepend= "WHERE" >
<isnotnull prepend= "and" property= "StartDate" >
A.act_time >= #startDate # and
a.act_time <= #endDate # and
a.id = b.id
</isNotNull>
</ Dynamic>
</select>
Correct approach: Narrow the scope, only to have the character conflict part of the legitimacy adjustment.
<select id= "Find" parameterclass= "Java.util.Map" resultclass= "Java.lang.Long" >
select IDs from
TableA a ,
TableB b
<dynamic prepend= "WHERE" >
<isnotnull prepend= "and" property= "StartDate" >
A.act_time >= #startDate #
<![ cdata[and A.act_time <= #endDate # ]]> and
a.id = b.id
</isNotNull>
</dynamic>
</select>
Summary: When using CDATA, just include the code that can produce a conflict, and don't blindly include it.
Reference from: http://hi.baidu.com/fwy434822/blog/item/614417f33a074bc00b46e047.html