mybatis plus querywrapper
时间: 2023-09-24 08:10:37 浏览: 236
MyBatis Plus QueryWrapper is a utility class provided by the MyBatis Plus framework to help in building complex database queries. It is used in conjunction with the MyBatis Plus Query API to construct criteria for selecting, updating, or deleting records from a database table.
QueryWrapper provides a fluent and intuitive API for constructing queries with various conditions such as equal, not equal, greater than, less than, between, like, and more. It also supports nested conditions and chaining multiple conditions together.
Here's an example of how to use QueryWrapper:
```java
// Import the necessary classes
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
// Create a QueryWrapper instance
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
// Add conditions to the query
queryWrapper
.eq("age", 25)
.like("name", "John")
.between("salary", 2000, 5000)
.orderByAsc("age");
// Use the query wrapper in your MyBatis Plus query
List<User> userList = userMapper.selectList(queryWrapper);
```
In this example, we create a QueryWrapper instance and chain different conditions like `eq`, `like`, and `between` to construct the desired query. Finally, we pass the query wrapper to the `selectList` method of the MyBatis Plus mapper interface to execute the query.
You can find more information about QueryWrapper and other features of MyBatis Plus in their official documentation.
阅读全文