myBatis 模糊查询like拼接

mybatis中模糊查询like拼接问题

<select id="getUsersByFuzzyQuery" parameterType="User" resultType="User">
    select <include refid="columns"/> from users
    <where>
        <!--
            方法一: 直接使用 % 拼接字符串 
        -->
        <if test="name != null">
            name like "%"#{name}"%"
        </if>
        <!--方法二: 使用concat(str1,str2)函数将两个参数连接 -->
        <if test="phone != null">
            and phone like concat(concat("%",#{phone}),"%")
        </if>
        <!--方法三: 使用 bind 标签-->
        <if test="email != null">
            <bind name="pattern" value="'%'+email+'%'"/>
            and email like #{pattern}
        </if>
    </where>
</select>

 


版权声明:本文为lsj1143956304原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。