说明
模糊查询,对应SQL语句中的 like
语句,模糊匹配“要查询的内容
”。
like
/**
* 查询用户列表, 查询条件:姓名包含 "J"
*/
@Test
void like() {
String name = "J";
LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
wrapper.like(StringUtils.hasText(name), User::getName, name);
List<User> users = mapper.selectList(wrapper);
log.info(users.toString());
}
notLike
/**
* 查询用户列表, 查询条件:姓名不包含 "J"
*/
@Test
void notLike() {
String name = "J";
LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
wrapper.notLike(StringUtils.hasText(name), User::getName, name);
List<User> users = mapper.selectList(wrapper);
log.info(users.toString());
}
likeLeft
/**
* 查询用户列表, 查询条件:左模糊查询,姓名以 "e" 结尾
*/
@Test
void likeLeft() {
String name = "e";
LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
wrapper.likeLeft(StringUtils.hasText(name), User::getName, name);
List<User> users = mapper.selectList(wrapper);
log.info(users.toString());
}
likeRight
/**
* 查询用户列表, 查询条件:右模糊查询,姓名以 "张" 开头
*/
@Test
void likeRight() {
String name = "张";
LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
wrapper.likeRight(StringUtils.hasText(name), User::getName, name);
List<User> users = mapper.selectList(wrapper);
log.info(users.toString());
}
notLikeLeft
/**
* 查询用户列表, 查询条件:左模糊查询,姓名不以 "e" 结尾
*/
@Test
void notLikeLeft() {
String name = "e";
LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
wrapper.notLikeLeft(StringUtils.hasText(name), User::getName, name);
List<User> users = mapper.selectList(wrapper);
log.info(users.toString());
}
notLikeRight
/**
* 查询用户列表, 查询条件:右模糊查询,姓名不以 "张" 开头
*/
@Test
void notLikeRight() {
String name = "张";
LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
wrapper.notLikeRight(StringUtils.hasText(name), User::getName, name);
List<User> users = mapper.selectList(wrapper);
log.info(users.toString());
}