当前位置: 移动技术网 > IT编程>数据库>Mysql > Mybatis特殊字符处理的详解

Mybatis特殊字符处理的详解

2017年12月07日  | 移动技术网IT编程  | 我要评论
前言: mybatis特殊字符处理,mybatis中xml文件特殊字符的处理,这里提供了解决办法及实例,大家可以参考下: 一、问题描述: 查询时,需要获取时间区间

前言:

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

一、问题描述:

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

<if test="starttime != null" > 
  and l.create_time >= #{starttime} 
</if> 
<if test="endtime != null" > 
   and l.create_time < #{endtime}  
</if> 

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

二、解决方案 

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

<![cdata[ 
   
]]> 

示例如下:

<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操作返回主键:

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

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

验证码:
移动技术网