赞
踩
QueryWrapper是MyBatis-Plus框架提供的一个查询构造器,可以用于构建复杂的查询条件,同时具有高度可定制的功能。下面是一些常见的用法和示例代码:
- QueryWrapper<User> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("name", "张三");
- List<User> userList = userMapper.selectList(queryWrapper);
- QueryWrapper<User> queryWrapper = new QueryWrapper<>();
- queryWrapper.like("name", "张");
- List<User> userList = userMapper.selectList(queryWrapper);
- QueryWrapper<User> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("age", 20).ne("status", "deleted");
- List<User> userList = userMapper.selectList(queryWrapper);
- QueryWrapper<User> queryWrapper = new QueryWrapper<>();
- queryWrapper.orderByAsc("age");
- List<User> userList = userMapper.selectList(queryWrapper);
- QueryWrapper<User> queryWrapper = new QueryWrapper<>();
- queryWrapper.eq("age", 20);
- Page<User> page = new Page<>(1, 10);
- IPage<User> userPage = userMapper.selectPage(page, queryWrapper);
- List<User> userList = userPage.getRecords();
- QueryWrapper<User> queryWrapper = new QueryWrapper<>();
- queryWrapper.inSql("id", "select user_id from user_role where role_id = 1");
- List<User> userList = userMapper.selectList(queryWrapper);
以上是一些常见的用法和示例代码,更多用法可以参考MyBatis-Plus的官方文档。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。