服务器之家:专注于服务器技术及软件下载分享
分类导航

Mysql|Sql Server|Oracle|Redis|MongoDB|PostgreSQL|Sqlite|DB2|mariadb|Access|数据库技术|

服务器之家 - 数据库 - Mysql - Mybatis特殊字符处理的详解

Mybatis特殊字符处理的详解

2020-08-02 18:34蕃薯耀 Mysql

这篇文章主要介绍了Mybatis特殊字符处理的详解的相关资料,需要的朋友可以参考下

前言:

Mybatis特殊字符处理,Mybatis中xml文件特殊字符的处理,这里提供了解决办法及实例,大家可以参考下:

一、问题描述:

查询时,需要获取时间区间内的数据,如下:

?
1
2
3
4
5
6
<if test="startTime != null" >
  and l.CREATE_TIME >= #{startTime}
</if>
<if test="endTime != null" >
   and l.CREATE_TIME < #{endTime} 
</if>

但是,Mybatis中xml 文件中,查询是不能使用小于号(<)的,因为这属于开始标签,是特殊字符

二、解决方案 

在查询中,使用CDATA包括起来,就能避免特殊字符了。这方法适用所有的特殊字符。

?
1
2
3
<![CDATA[
   
]]>

示例如下:

?
1
2
3
4
5
6
7
8
9
10
<if test="startTime != null" >
  <![CDATA[
    and l.CREATE_TIME >= #{startTime}
  ]]>
</if>
<if test="endTime != null" >
  <![CDATA[
  and l.CREATE_TIME < #{endTime}
  ]]>
</if>

MyBatis返回主键,MyBatis Insert操作返回主键:

感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

原文链接:http://fanshuyao.iteye.com/blog/2319849

延伸 · 阅读

精彩推荐