目的:XML中不希望转义的SQL可以写入<![CDATA[ ]]括号里面,比如where中常用的>、<=、& 等字符。因为写在[ ]里面的内容会被解析器忽略。
注意:<if>、<where> 等标签不要写里面,因为这些标签页不会被解析。尽量简化<![CDATA[ ]]> 中的代码。
<select id="selectByTS" resultMap="BaseResultMap" parameterType="com.tianrui.dc.dao.nc.bean.BdCustorg">
select
<include refid="Base_Column_List" />
from BD_STORDOC tti
<where>
<if test="enablestate !=null and enablestate !=''">
enablestate =#{enablestate,jdbcType=DECIMAL}
</if>
<if test='maxTs != null and maxTs!="" '>
<![CDATA[and to_date(tti.ts,'yyyy/mm/dd hh24:mi:ss') >to_date(#{maxTs},'yyyy/mm/dd hh24:mi:ss')]]>
</if>
</where>
</select>
本文介绍如何在XML文件中利用CDATA段落来包含特殊字符,避免它们被XML解析器误解释。通过示例展示了如何正确书写SQL语句片段,特别关注在MyBatis中的应用。
6637

被折叠的 条评论
为什么被折叠?



