mybatis 转义符号 条件判断
1.用转义字符把>和<替换掉
mybatis中的mapper里面,条件判断符号
字段 | 符号 | 说明 |
---|---|---|
< ; | < | 小于号 |
> ; | > | 大于号 |
& ; | & | 和 |
&apos ; | ’ | 单引号 |
" ; | " | 双引号 |
//原SQL
select * from table where createTime >'2019-10-10' and createTime <= '2019-10-20'
//修改后SQL:
select * from table where createTime > '2019-10-10' and createTime <= '2019-10-20'
2.增加声明标志:<![CDATA[]]>
被<![CDATA[]]>这个标记所包含的内容将表示为纯文本,后台会原样解析并执行
SELECT *FROM table
<where>
<!-- 录入日期 范围 -->
<if test="date_st != '' and date_ed != ''">
<![CDATA[
and createTime >= #{date_st} and createTime =< #{date_ed}
]]>
</if>
</where>
链接: 参考.