1. 程式人生 > >MyBatis中xml檔案中模糊查詢的寫法

MyBatis中xml檔案中模糊查詢的寫法

資料庫中某表的一個欄位為name,我需要對它進行模糊查詢的時候使用了下面的方法,解決了這個問題。

<select id="findList" resultType="DwfxGzysxl">  
	SELECT   
		<include refid="dwfxGzysxlColumns"/>  
 	FROM v_dwfx_gzysxl a  
	<include refid="dwfxGzysxlJoins"/>  
	<where>  
		<if test="name != null and name != ''">  
		AND a.name LIKE   
			<if test="dbName == 'oracle'">'%'||#{name}||'%'</if>  
			<if test="dbName == 'mssql'">'%'+#{name}+'%'</if>  
			<if test="dbName == 'mysql'">concat('%',#{name},'%')</if>  
		</if>  
	</where>  
        <choose>  
		<when test="page !=null and page.orderBy != null and page.orderBy != ''">  
			ORDER BY ${page.orderBy}  
		</when>  
	</choose>  
</select>