Mybatis:大于号、小于号的转义写法

在Mybatis中,sql语句的 大于号(>),小于号(<),在xml文件中是特殊字符(< >),所以需要做转义。

使用xml的转义字符方法:<![CDATA[  特殊字符  ]]>。

示例:

	<select id="getListCount" resultType="int" parameterType="java.util.HashMap">
		SELECT * FROM V_gsuserbanding AS tm WHERE 1=1 
		<if test="UserName !=null and UserName !=''">
		and UserName like "%"#{UserName}"%"
		</if>
		<if test="BeginTime !=null and BeginTime !=''">
		and CreateTime <![CDATA[ >= ]]> #{BeginTime} -- 转义 >=
		</if>
		<if test="EndTime !=null and EndTime !=''">
		and CreateTime <![CDATA[ <= ]]> #{EndTime} -- 转义 <=
		</if>		
	</select>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章