Young87

SmartCat's Blog

So happy to code my life!

游戏开发交流QQ群号60398951

当前位置:首页 >跨站数据

Mybatis的mapper.xml文件中不能使用小于等特殊字符时该怎么办?

今天在写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

上一篇: 史上最简单的SpringCloud教程 | 第八篇: 消息总线(Spring Cloud Bus)

下一篇: 关于deepin外放有声音,耳机没有声音的奇葩解决方案

精华推荐