条件构造器QueryWrapper
时间: 2023-10-09 10:08:26 浏览: 96
mybatis plus条件构造器queryWrapper、updateWrapper
QueryWrapper是MyBatis-Plus中提供的一个条件构造器,它可以方便地构造查询条件。其主要使用方法和参数如下:
1. 创建QueryWrapper对象
```
QueryWrapper<T> queryWrapper = new QueryWrapper<>();
```
其中,T为查询的实体类。
2. 设置查询条件
- 等值查询
```
queryWrapper.eq("column", value);
```
- 不等值查询
```
queryWrapper.ne("column", value);
```
- 大于查询
```
queryWrapper.gt("column", value);
```
- 大于等于查询
```
queryWrapper.ge("column", value);
```
- 小于查询
```
queryWrapper.lt("column", value);
```
- 小于等于查询
```
queryWrapper.le("column", value);
```
- 模糊查询
```
queryWrapper.like("column", value);
```
- IN查询
```
queryWrapper.in("column", list);
```
- NOT IN查询
```
queryWrapper.notIn("column", list);
```
- BETWEEN查询
```
queryWrapper.between("column", value1, value2);
```
- NOT BETWEEN查询
```
queryWrapper.notBetween("column", value1, value2);
```
- IS NULL查询
```
queryWrapper.isNull("column");
```
- IS NOT NULL查询
```
queryWrapper.isNotNull("column");
```
- EXISTS查询
```
queryWrapper.exists("subQuerySql");
```
- NOT EXISTS查询
```
queryWrapper.notExists("subQuerySql");
```
3. 设置排序
```
queryWrapper.orderByAsc("column1", "column2", ...);
queryWrapper.orderByDesc("column1", "column2", ...);
```
4. 设置分页
```
queryWrapper.page(page);
queryWrapper.last("limit " + pageSize * (pageNo - 1) + "," + pageSize);
```
5. 执行查询
```
List<T> list = mapper.selectList(queryWrapper);
```
阅读全文