<!--Mapper.xml中如何進行模糊查詢-->
<sql id="brand_columns">
id, name, firstChar,brandName
</sql>
<select id="selectBrand" parameterType="com.lf.Brand" resultType="com.lf.Brand">
select <include refid="brand_columns"/> from tb_brand
<where>
<!-- 直接使用 % 拼接字符串 -->
<!-- 錯誤寫法 "%#{name}%",正確寫法: "%"#{name}"%",即#{name}能夠正確解析出來,前后再拼上%即可-->
<if test="name != null">
name like "%"#{name}"%"
</if>
<!concat(str1,str2)函數將兩個參數連接 -->
<if test="firstChar != null">
and first_char like concat(concat("%",#{firstChar}),"%")
</if>
<! bind 標簽,對字符串進行綁定,對綁定后的字符串使用 like 關鍵字進行模糊查詢 -->
<if test="brandName != null">
<bind name="likeBrandName" value="'%'+brandName+'%'"/>
and brand_name like #{brandName}
</if>
</where>
</select>