mybatis的mapper的特殊符号处理
mybatis 处理 Mapper 特殊符号
2023-09-11 14:18:56 时间
这种问题在xml处理sql的程序中经常需要我们来进行特殊处理。
其实很简单,我们只需作如下替换即可避免上述的错误:
< | <= | > | >= | & | ' | " |
< |
<= |
> |
>= |
& |
' |
" |
备注:>=号可以直接在mapper中写,比如:
<if test="platformGoods.last_time == null">
and opg.last_modified >= (date_sub(NOW(), interval '0
0:30:0' day_second))
</if>
备注: 对于>、<、<=都需要转义或者加标签。对于>=号可以直接用,所以我们在项目中如果是<=则将这个转换下转成>=来写在mapper中。
例如常见的时间比较:
错误写法
- <select id="select" parameterType="xxx" resultMap="xxx">
- select
- distinct
- <include refid="Base_Column_List" />
- from xxx
- <where>
- <if test="createDate != null">
- create_date <= #{createDate}
- </if>
- </where>
- </select>
正确写法
- <select id="select" parameterType="xxx" resultMap="xxx">
- select
- distinct
- <include refid="Base_Column_List" />
- from xxx
- <where>
- <if test="createDate != null">
- create_date <= #{createDate}
- </if>
- </where>
- </select>
相关文章
- Mybatis 在线生成
- MyBatis 缓存
- [转]Mybatis foreach 批量操作
- 关于Mybatis中的xml中的大于号,小于号处理方法
- MyBatis 配置文件
- MyBatis Plus 添加多租户功能后 对某个Mapper方法 忽略多租户处理 使用注解 @InterceptorIgnore(tenantLine = "true")
- springboot(七):springboot+mybatis多数据源最简解决方案
- mybatis generator配置,Mybatis自动生成文件配置,Mybatis自动生成实体Bean配置
- MyBatis 缓存
- 解决idea创建ssm项目找不到mybatis的mapper的xml文件问题
- mybatis include refid="Base_Column_List"含义
- Mybatis 中的 @Mapper, @MapperScan, @Repository,mybatis.mapper-locations 的用法与区别
- vue实战入门后台篇八:springboot+mybatis实现网站后台-客户端界面数据对接
- SSM框架——详细整合教程(Spring+SpringMVC+MyBatis)
- Mybatis_mybatis常用jdbcType数据类型
- mybatis使用记录:#{}与${}区别、缓存机制、传递数组参数和List参数时if-test判空和判断长度的写法、Mybatis查询数据返回基本类型数组
- SpringBoot+Mybatis+mybatis generate+oracle
- Mybatis动态SQL(where元素、set元素、if元素)
- 【Redis】SpringBoot+MyBatis集成Redis二级缓存
- SpringBoot整合SpringMVC+MyBatis
- 从mybatis源码看JDK动态代理
- springboot+mybatis整合(单元测试,异常处理,日志管理,AOP)
- MyBatis-Plus Lambda 常用查询