MybatisPlus学习-条件构造器
转载
MybatisPlus学习-条件构造器
测试用例
@SpringBootTest
public class WrapperTest {
@Autowired
private UserMapper userMapper;
@Test
void contextLoads(){
//age大于12
QueryWrapper<User> wrapper = new QueryWrapper<>();
wrapper.isNotNull("name")
.isNotNull("email")
.ge("age",12);
userMapper.selectList(wrapper).forEach(System.out::println);
}
@Test
void test2(){
QueryWrapper<User> wrapper = new QueryWrapper<>();
wrapper.eq("name","gui");
User user = userMapper.selectOne(wrapper);//查询一个,多个用selectList
System.out.println(user);
}
@Test
void test3(){
//age在20~30
QueryWrapper<User> wrapper = new QueryWrapper<>();
wrapper.between("age",20,30);
Integer count = userMapper.selectCount(wrapper);
System.out.println(count);
}
@Test
void test4(){
//age在20~30
QueryWrapper<User> wrapper = new QueryWrapper<>();
wrapper.notLike("name","e") //不存在e
.likeRight("email","1");//以1开始
userMapper.selectMaps(wrapper).forEach(System.out::println);
}
@Test
void test5(){
//age在20~30
QueryWrapper<User> wrapper = new QueryWrapper<>();
//id 在子查询查出来
wrapper.inSql("id","select id from user where id<3");
List<Object> objects = userMapper.selectObjs(wrapper);
objects.forEach(System.out::println);
}
@Test
void test6(){
//id 降序排序
QueryWrapper<User> wrapper = new QueryWrapper<>();
wrapper.orderByDesc("id");
List<User> users = userMapper.selectList(wrapper);
users.forEach(System.out::println);
}
}
本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。