mapper中
<select id="findUserByLikeName1" parameterType="java.lang.String" resultMap="user">
select * from t_user where name like #{name}
</select>
java中
List<User> test = userMapper.findUserByLikeName1("%" +name+"%");
mapper中
<select id="findUserByLikeName2" parameterType="java.lang.String" resultMap="user">
select * from t_user where name like concat('%', #{name}, '%')
</select>
java中
List<User> test = userMapper.findUserByLikeName2(name);
mapper中
<select id="findUserByLikeName3" parameterType="java.lang.String" resultMap="user">
select * from t_user where INSTR(name, #{name}) > 0
</select>
java中
List<User> test = userMapper.findUserByLikeName3(name);
方法1,2如果name参数为 % 或者 _ 通配符时,筛选会失效,将检索出全部数据,解决办法:Mybatis 拦截器实现 Like 通配符转义