MyBatis - 在Xml中实现模糊查询

一、文本替换模式(有SQL注入风险)

<if test="title != null and title != ''">
		AND title like '%${title}%'
</if>

二、使用 Bind 标签

<if test="title != null and title != ''">
	<bind name="titleLike" value="'%' + title + '%'" />
	AND title like #{titleLike}
</if>

三、使用 concat 函数(Oracle的concat函数只支持两个参数,考虑使用两次)

<if test="title != null and title != ''">
		AND title like concat('%',#{title},'%')
</if>

 

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