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

 

 

 

相关文章:

  • 2021-11-23
  • 2021-08-02
  • 2021-08-04
  • 2021-12-02
  • 2021-09-23
  • 2021-07-12
  • 2022-12-23
  • 2021-05-28
猜你喜欢
  • 2021-10-16
  • 2022-12-23
  • 2021-09-14
  • 2021-10-16
  • 2021-05-14
相关资源
相似解决方案