Mybatis特殊字符处理,Mybatis中xml文件特殊字符的处理

Mybatis特殊字符处理,Mybatis中xml文件特殊字符的处理

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

蕃薯耀 2016年8月24日 10:18:51 星期三

http://fanshuyao.iteye.com/

一、问题描述:

查询时,需要获取时间区间内的数据,如下:

<if test="startTime != null" >
    and l.CREATE_TIME >= #{startTime}
</if>
<if test="endTime != null" >
     and l.CREATE_TIME < #{endTime} 
</if>

但是,Mybatis中xml 文件中,查询是不能使用小于号(<)的,因为这属于开始标签,是特殊字符

二、解决方案

在查询中,使用CDATA包括起来,就能避免特殊字符了。这方法适用所有的特殊字符。

<![CDATA[ 
	
]]>

示例如下:

<if test="startTime != null" >
    <![CDATA[ 
        and l.CREATE_TIME >= #{startTime}
    ]]>
</if>
<if test="endTime != null" >
    <![CDATA[ 
	and l.CREATE_TIME < #{endTime} 
    ]]>
</if>

MyBatis返回主键,MyBatis Insert操作返回主键:

http://fanshuyao.iteye.com/blog/2245853

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

蕃薯耀 2016年8月24日 10:18:51 星期三

http://fanshuyao.iteye.com/

猜你喜欢

转载自fanshuyao.iteye.com/blog/2319849