模糊查询怎么写
1、Java代码执行的时候,传递通配符% %
@Test
public void getUserLike(){
SqlSession sqlSession=MybatisUtils.getSqlSession();
UserMapper mapper=sqlSession.getMapper(UserMapper.class);
List<User> userLike = mapper.getUserLike("%李%");
for (User user : userLike) {
System.out.println(user);
}
sqlSession.close();
}
2、在sql拼接中使用通配符!
将上面测试类中的% %去掉
<select id="getUserLike" resultType="com.lding.pojo.User">
select *
from mybatis.user where name like "%"#{value}"%";
</select>