1. 程式人生 > >mybatis多條件模糊查詢

mybatis多條件模糊查詢

<select id="selectUserList" parameterType="cn.vipkes.dao.dto.param.UserListDto" resultType="cn.vipkes.dao.dto.result.UserListResult">
		SELECT USER_NAME as userName
		FROM USER
		WHERE DEL_FLG = 0
		<if test="userName != null and userName != ''">
			AND USER_NAME LIKE '%'||#{userName}||'%'
		</if>
		<if test="address != null and address != ''">
			AND ADDRESS LIKE '%'||#{address}||'%'
		</if>
	</select>

如上,通過使用者名稱(username)和地址(address)多條件模糊查詢。

注意的是,想要拼接 %  那就像如上方式去寫,蠻好的,哈哈~