1,selectOne()方法。
根据 QueryWrapper 的条件 查询返回一条数据,查询出多条数据则报错。
QueryWrapper<T> queryWrapper = new QueryWrapper<T>();
User user = userMapper.selectOne(QueryWrapper < T > queryWrapper);
SQL 语句如下:
==> Preparing: SELECT id,name,sex,age,address FROM user WHERE (id = ?)
==> Parameters: 13(Integer)
<== Total: 0
2,selectList()方法。
根据 QueryWrapper 的条件 查询返回多条数据(List<T> 集合)。
QueryWrapper<T> queryWrapper = new QueryWrapper<T>();
List<User> users = userMapper.selectList(QueryWrapper<T> queryWrapper);
SQL 语句如下:
==> Preparing: SELECT id,name,sex,age,address FROM user WHERE (age > ?)
==> Parameters: 12(Integer)
<== Columns: id, name, sex, age, address
<== Row: 7, null, 男, 13, kks
<== Row: 8, null, 男, 13, kks
<== Total: 2
3,selectCount()方法。
根据 QueryWrapper 的条件 查询返回总数据的条数。
QueryWrapper<T> queryWrapper = new QueryWrapper<T>();
Integer integer = userMapper.selectCount(QueryWrapper < T > queryWrapper);
SQL 语句如下:
==> Preparing: SELECT COUNT( * ) FROM user WHERE (age > ?)
==> Parameters: 12(Integer)
<== Columns: COUNT( * )
<== Row: 2
<== Total: 1
4,selectMaps()方法。
根据 QueryWrapper 的条件 查询返回多条数据(List<Map<String,Object>> ListMap集合)。
QueryWrapper<T> queryWrapper = new QueryWrapper<T>();
List<Map<String, Object>> maps = userMapper.selectMaps(QueryWrapper < T > queryWrapper);
SQL 语句如下:
==> Preparing: SELECT id,name,sex,age,address FROM user WHERE (age > ?)
==> Parameters: 12(Integer)
<== Columns: id, name, sex, age, address
<== Row: 7, null, 男, 13, kks
<== Row: 8, null, 男, 13, kks
<== Total: 2
{address=kks, sex=男, id=7, age=13}
{address=kks, sex=男, id=8, age=13}
5,selectByMap()方法。
根据 columnMap 封装的条件 查询返回多条数据(List<T> 集合)。
Map<String, Object> columnMap = new HashMap<>();
columnMap.put("id", 7);
columnMap.put("sex", "男");
List<User> users = userMapper.selectByMap(Map<String, Object>columnMap);
SQL 语句如下:
==> Preparing: SELECT id,name,sex,age,address FROM user WHERE sex = ? AND id = ?
==> Parameters: 男(String), 7(Integer)
<== Columns: id, name, sex, age, address
<== Row: 7, null, 男, 13, kks
<== Total: 1
6,selectById()方法。
根据传入的 id 进行查询 查询成功返回单条数据,否则返回 null
User user = userMapper.selectById(Serializable id);
SQL 语句如下:
==> Preparing: SELECT id,name,sex,age,address FROM user WHERE id=?
==> Parameters: 7(Integer)
<== Columns: id, name, sex, age, address
<== Row: 7, null, 男, 13, kks
<== Total: 1
7,selectBatchIds()方法。
根据传入的 idList 集合 进行查询返回多条数据(List<T> 集合)。。
List<Integer> idList = new ArrayList<>();
idList.add(5);
idList.add(6);
List<User> users = userMapper.selectBatchIds(Collection<? extends Serializable> idList);
SQL 语句如下:
==> Preparing: SELECT id,name,sex,age,address FROM user WHERE id IN ( ? , ? )
==> Parameters: 5(Integer), 6(Integer)
<== Total: 0
8,selectPage()方法。
9,selectMapsPage()方法。
10,QueryWrapper 的使用。
10.1, allEq() 方法。
allEq( Map < String, Object > params )
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
// 封装的条件 即便 map 参数的值为 null 仍然查询
Map<String, Object> map = new HashMap<>();
map.put("id", 7);
map.put(&