Mybatis的mapper.xml文件中不能使用小于等特殊字符时该怎么办?
日期: 2017-04-12 分类: 跨站数据 260次阅读
今天在写Mybatis相关mpper.xml文件时,发现不能在mapper文件中使用小于符号,原情景如下:
这样写xml直接报错(具体报错见loginDateLast字段):
<sql id="pubUserLoginLogSelectCondition">
<where>
<if test="id != null">and id = #{id}</if>
<if test="comId != null"> and comId = #{comId}</if>
<if test="sysEmpId != null"> and sysEmpId = #{sysEmpId}</if>
<if test="account != null"> and account = #{account}</if>
<if test="name != null"> and name = #{name}</if>
<if test="status != null"> and `status` = #{status}</if>
<if test="loginDateStart != null"> and loginDate >= #{loginDateStart}</if>
<if test="loginDateLast != null">and loginDate <= #{loginDateLast}> </if>
<if test="loginIp != null"> and loginIp = #{loginIp}</if>
<if test="reason != null"> and reason = #{reason}</if>
</where>
order by loginDate DESC
</sql>
后来,再同事的帮助下,只需要在转义的字符情况下加上<![CDATA[ ]]>括起来即可:
更正后:
<sql id="pubUserLoginLogSelectCondition">
<where>
<if test="id != null">and id = #{id}</if>
<if test="comId != null"> and comId = #{comId}</if>
<if test="sysEmpId != null"> and sysEmpId = #{sysEmpId}</if>
<if test="account != null"> and account = #{account}</if>
<if test="name != null"> and name = #{name}</if>
<if test="status != null"> and `status` = #{status}</if>
<if test="loginDateStart != null"> and loginDate >= #{loginDateStart}</if>
<if test="loginDateLast != null"><![CDATA[ and loginDate <= #{loginDateLast}]]></if>
<if test="loginIp != null"> and loginIp = #{loginIp}</if>
<if test="reason != null"> and reason = #{reason}</if>
</where>
order by loginDate DESC
</sql>
除特别声明,本站所有文章均为原创,如需转载请以超级链接形式注明出处:SmartCat's Blog
精华推荐