<!--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>