mybatis在xml文件中处理大于小于号的方法

第一种

用转移字符把“>”和“<”替换掉

  <if test='strSettMonth!=null  and strSettMonth!=\"\" '>
              and  sett_month &gt;=  #{strSettMonth,jdbcType=VARCHAR}  
            </if>
            <if test='endSettMonth!=null and endSettMonth!=\"\"  '>
              and  sett_month &lt;=  #{endSettMonth,jdbcType=VARCHAR}  
            </if>"

sett_month是varchar类型;

附:XML转义字符

&lt;      <    小于号   
&gt;      >    大于号   
&amp;      &    和   
&apos;      ’    单引号   
&quot;      "    双引号   


第二种

因为这是xml格式的,所以不允许出现类似">"这样的字符,但是可以使用<![CDATA[ ]]>符号进行说明,将此类符号不进行解析

mapper文件示例代码

<if test="startTime != null ">
    AND <![CDATA[ order_date >= #{startTime,jdbcType=DATE}  ]]>
</if>
<if test="endTime != null ">
    AND <![CDATA[ order_date <= #{endTime,jdbcType=DATE}  ]]>
</if>




猜你喜欢

转载自blog.csdn.net/u010931123/article/details/80748857