赞
踩
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.x.x</version>
</dependency>
LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(User::getName, "张三");
等价于SQL语句:
SELECT * FROM user WHERE name = '张三';
(2)ne方法:不等于查询
wrapper.ne(User::getAge, 18);
等价于SQL语句:
SELECT * FROM user WHERE age <> 18;
(3)gt方法:大于查询
wrapper.gt(User::getAge, 18);
等价于SQL语句:
SELECT * FROM user WHERE age > 18;
(4)ge方法:大于等于查询
wrapper.ge(User::getAge, 18);
等价于SQL语句:
SELECT * FROM user WHERE age >= 18;
(5)lt方法:小于查询
wrapper.lt(User::getAge, 18);
等价于SQL语句:
SELECT * FROM user WHERE age < 18;
(6)le方法:小于等于查询
wrapper.le(User::getAge, 18);
等价于SQL语句:
SELECT * FROM user WHERE age <= 18;
(7)like方法:模糊查询
wrapper.like(User::getName, "张%");
等价于SQL语句:
SELECT * FROM user WHERE name LIKE '张%';
(8)in方法:IN查询
List<String> names = Arrays.asList("张三", "李四", "王五");
wrapper.in(User::getName, names);
等价于SQL语句:
SELECT * FROM user WHERE name IN ('张三', '李四', '王五');
wrapper.eq(User::getName, "张三").and(wrapper1 -> wrapper1.gt(User::getAge, 18));
等价于SQL语句:
SELECT * FROM user WHERE name = '张三' AND age > 18;
(2)or方法:OR组合查询条件
wrapper.eq(User::getName, "张三").or(wrapper1 -> wrapper1.gt(User::getAge, 18));
等价于SQL语句:
SELECT * FROM user WHERE name = '张三' OR age > 18;
wrapper.orderByAsc(User::getAge);
等价于SQL语句:
SELECT * FROM user ORDER BY age ASC;
(2)orderByDesc方法:降序排序
wrapper.orderByDesc(User::getAge);
等价于SQL语句:
SELECT * FROM user ORDER BY age DESC;
(3)last方法:在查询语句的最后面添加SQL语句
wrapper.last("LIMIT 10");
等价于SQL语句:
SELECT * FROM user LIMIT 10;
(4)page方法:分页查询
Page<User> page = new Page<>(1, 10);
wrapper.eq(User::getName, "张三").page(page);
其中,第一个参数表示当前页数,第二个参数表示每页显示的记录数。
List<User> list = userMapper.selectList(wrapper);
其中,userMapper是一个继承了MyBatis-Plus提供的BaseMapper的接口,可以直接调用selectList方法进行查询操作。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。