mybatis - [07] 模糊查询
题记部分
(1)mapper类
List<User> getUserLike(String value);
(2)mapper.xml
<!-- 写法1 -->
<select id="getUserLike" resultType="com.harley.pojo.User">
select * from user where name like #{value}
</select>
<!-- 写法2 -->
<select id="getUserLike" resultType="com.harley.pojo.User">
select * from user where name like '%${value}%'
</select>
(3)测试类
代码执行的时候使用通配符
%keyword%
// 写法1
@Test
public void getUserLike(){
List<User> userList = userMapper.getUserLike("%日%");
for (User user : userList) {
System.out.println(user.toString());
}
}
// 写法2
@Test
public void getUserLike(){
List<User> userList = userMapper.getUserLike("日");
for (User user : userList) {
System.out.println(user.toString());
}
}
— 业精于勤荒于嬉,行成于思毁于随 —