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>

 

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