mybatis plus LambdaQueryWrapper
时间: 2023-10-02 12:05:38 浏览: 212
Mybatis Plus LambdaQueryWrapper is a part of the Mybatis Plus library that provides a more expressive and type-safe way to construct SQL queries. It allows you to build complex queries using lambda expressions and method chaining, eliminating the need for writing raw SQL statements.
The LambdaQueryWrapper class provides various methods to specify conditions, such as `eq`, `ne`, `gt`, `ge`, `lt`, `le`, `like`, `in`, `notIn`, etc., which correspond to the SQL operators. You can chain these methods together to create complex query conditions.
Here's an example of how to use LambdaQueryWrapper:
```java
LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
queryWrapper.eq(User::getAge, 25)
.like(User::getName, "John")
.lt(User::getSalary, 5000);
List<User> users = userMapper.selectList(queryWrapper);
```
In this example, we create a LambdaQueryWrapper and specify the conditions using lambda expressions. We filter the users based on age, name, and salary. Finally, we pass the query wrapper to the selectList method of the userMapper to retrieve the matching users.
LambdaQueryWrapper provides a convenient and type-safe approach to construct SQL queries in Mybatis Plus, making the code more readable and maintainable.
阅读全文