MyBatis【付诸实践 01】mapper.xml 中特殊符号的 2 种处理方法(CDATA区+替代字符举例)
# ... .. . MyBatis . .. ...,xml,sql,java,mybatis 额外说明
收录于:193天前
1. CDATA区
全称为 CHARACTER DATA,可以在两者之间嵌入不想被程序解析的数据,解析器会将这些数据原封不动地交给下游程序处理,举例如下:
& 且: <![CDATA[ & ]]>
<= 小于等于:<![CDATA[ <= ]]>
>= 大于等于:<![CDATA[ >= ]]>
2. 替代符号
在 XML 文件内使用替代符号,举例如下:
3. 使用举例
- 原始SQL
createTime >= beginDate and createTime <= endDate
- CDATA区使用
<if test="beginDate != null ">
and createTime <![CDATA[ >= ]]> #{beginDate}
</if>
<if test="endDate != null ">
and createTime <![CDATA[ <= ]]> #{endDate}
</if>
或
<if test="beginDate != null ">
and <![CDATA[ createTime >= #{beginDate} ]]>
</if>
<if test="endDate != null ">
and <![CDATA[ createTime <= #{endDate} ]]>
</if>
- 替代符号使用
<if test="beginDate != null ">
and createTime >= #{beginDate}
</if>
<if test="endDate != null ">
and createTime <= #{endDate}
</if>
. . .
相关推荐
热门推荐
SpringBoot+actuator和...
201天前
PostgreSQL 11 新特性之分区...
200天前
spring之Spring与消息队列
196天前
随机数生成
196天前
创建获取Springbean对象工具类
196天前
编程工具(一)--------Postm...
196天前
分布式锁使用场景以及实现方式
196天前
Go语言小程序
196天前
算法刷题-分隔链表、合并两个有序链表、在...
196天前
在GitHub上fork项目后,如何与原...
196天前
最新推荐
基于webrtc的前端录屏和直播
199天前
GIT02_分布式版本控制工具Git安装
199天前
运行eeui项目不出现 WiFI真机同步...
196天前
VC++把程序“消失的”窗口“拽”出来显...
196天前
idea 左下角的Git(Version...
196天前
Java的23种设计模式
196天前
【Rust 基础篇】Rust Optio...
196天前
如何在WordPress中使用Blogr...
188天前
ads via 小工具