MyBatis中特殊符号的转义
在MyBatis中遇到特殊符号时有两种转义⽅式:
第⼀种
描述空格⼩于⼤于⼩于等于⼤于等于与单引号双引号原符号<><=>=&'"
替换符号 <><=>=&'";例如:
<select id = "selectUserByAge" resultType="del.UserTable" >
select
id,userName,age
from
userTable
<where>
IS_DELETE = 1
/*时间段查询*/
<if test = "userTable.startDate!=null">
and SIGNING_DATE >= #{userTable.startDate}
</if>
<if test = "dDate != null">
and SIGNING_DATE <= #{dDate}
</if>
</where>
</select>
记住我第⼆种
使⽤ <![CDATA[>=]]> 进⾏转义
例如:
<select id = "selectUserByAge" resultType="del.UserTable" >
select
id,userName,age
from
userTable
<where>
IS_DELETE = 1
/*时间段查询*/
<if test = "userTable.startDate != null">
and SIGNING_DATE <![CDATA[>=]]> #{userTable.startDate}
</if>
<if test = "dDate!=null">
and SIGNING_DATE <![CDATA[<=]]> #{dDate}
</if>
</where>
</select>