mybatis在mapper.xml中怎么处理大于、小于、不等于号

第一种方法:
使用转义字符

大于号 > >
大于等于号 >= >=
小于号 < &lt; 
小于等于号 <= &lt;=
与 & &amp;
双引号 " &quot;
单引号 ' &apos;

例子:

 <if test="beginTimeStr != null">
    and file.created_at &gt;= '${beginTimeStr}'
</if>
<if test="endTimeStr != null">
    and file.created_at &lt;= '${endTimeStr}'
</if>

第二种方法:
使用<![CDATA[  ]]>
因为xml格式遇到这种格式会把方括号里的内容原样输出,不进行解析,如:

大于等于    <![CDATA[ >= ]]>
小于等于     <![CDATA[ <= ]]>
例如:sql如下:

<if test="beginTimeStr != null">
    <![CDATA[ and file.created_at >= '${beginTimeStr}' ]]>
</if>
<if test="endTimeStr != null">
    <![CDATA[ and file.created_at <= '${endTimeStr}' ]]>
</if>

 

posted @   study_php_java_C++  阅读(5444)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2022-06-20 【vue】监听元素进入视口
2022-06-20 当在vue项目中使用滚动监听时,页面跳转后,报错Uncaught TypeError: Cannot read property ‘offsetTop‘ of undefined at VueComp
2022-06-20 vue scrollTop为0及window视图
2019-06-20 微信小程序生成小程序某一个页面的小程序码
点击右上角即可分享
微信分享提示