Mybatis关于like的处理
程序员文章站
2022-06-02 20:12:43
...
1、利用"%"对入参进行拼接
2、SQL语句字符串拼接
SELECT * FROM tableName WHERE name LIKE CONCAT(CONCAT('%', #{text}), '%');
3、bind标签
<select id="findUserByFuzzyEmail" resultMap="BaseResultMap"
parameterType="java.lang.String">
select id,username,email,status,createtime,updatetime from tb_user
<bind name="pattern" value="'%'+_parameter.getEmail() +'%'" />
<where>
<if test="email != null and email != ''">
email like #{pattern}
</if>
</where>
</select>