LambdaQueryWrapper最多的用法
时间: 2023-05-23 11:05:04 浏览: 198
LambdaQueryWrapper 是 MyBatis-Plus 提供的一个查询构造器,用于快速构建查询条件。它最常用的用法有以下几种:
1. 等值条件查询:
```java
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(User::getName, "张三");
List<User> userList = userMapper.selectList(queryWrapper);
```
2. 模糊查询:
```java
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().like(User::getName, "张%");
List<User> userList = userMapper.selectList(queryWrapper);
```
3. 范围查询:
```java
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().between(User::getAge, 18, 25);
List<User> userList = userMapper.selectList(queryWrapper);
```
4. 排序查询:
```java
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().orderByDesc(User::getCreateTime);
List<User> userList = userMapper.selectList(queryWrapper);
```
5. 分页查询:
```java
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.lambda().eq(User::getSex, 1).last("limit 10, 20");
List<User> userList = userMapper.selectList(queryWrapper);
```
这些使用方式涵盖了 LambdaQueryWrapper 最常用的功能,使用起来非常方便,能大大提高开发效率。
阅读全文