mybatisplus常用函数
时间: 2023-09-05 22:08:42 浏览: 146
MyBatis-Plus 是 MyBatis 的增强工具库,提供了许多实用的函数。下面是一些常用的函数:
1. eq:等于
```
QueryWrapper<User> wrapper = new QueryWrapper<>();
wrapper.eq("name", "张三");
```
2. ne:不等于
```
QueryWrapper<User> wrapper = new QueryWrapper<>();
wrapper.ne("age", 18);
```
3. gt:大于
```
QueryWrapper<User> wrapper = new QueryWrapper<>();
wrapper.gt("age", 18);
```
4. ge:大于等于
```
QueryWrapper<User> wrapper = new QueryWrapper<>();
wrapper.ge("age", 18);
```
5. lt:小于
```
QueryWrapper<User> wrapper = new QueryWrapper<>();
wrapper.lt("age", 18);
```
6. le:小于等于
```
QueryWrapper<User> wrapper = new QueryWrapper<>();
wrapper.le("age", 18);
```
7. like:模糊查询
```
QueryWrapper<User> wrapper = new QueryWrapper<>();
wrapper.like("name", "张");
```
8. notLike:不匹配查询
```
QueryWrapper<User> wrapper = new QueryWrapper<>();
wrapper.notLike("name", "张");
```
9. in:包含查询
```
QueryWrapper<User> wrapper = new QueryWrapper<>();
wrapper.in("age", 18, 20, 22);
```
10. notIn:不包含查询
```
QueryWrapper<User> wrapper = new QueryWrapper<>();
wrapper.notIn("age", 18, 20, 22);
```
11. orderBy:排序
```
QueryWrapper<User> wrapper = new QueryWrapper<>();
wrapper.orderByAsc("age");
```
12. select:查询指定列
```
QueryWrapper<User> wrapper = new QueryWrapper<>();
wrapper.select("id", "name");
```
13. last:拼接 SQL 语句
```
QueryWrapper<User> wrapper = new QueryWrapper<>();
wrapper.last("limit 1");
```
14. exists:子查询
```
QueryWrapper<User> wrapper = new QueryWrapper<>();
wrapper.exists("select 1 from user_role where user_id=user.id and role_id=1");
```
阅读全文