通过入参中包含一个IPage对象完成分页查询(不需要自己去写分页语句).不过需要注意的是,返回值是一个List对象,所以在ServicecImpl中要通过调用IPage的setRecords方法,将查询结果放入IPage对象中. 联表查询 MyBatisPlus的联表查询也非常方便,下面我会以一个视频表(t_video)为例,表的结构如下: 其中用户id是用户表的...
QueryWrapper<Employee> andWrapper = new QueryWrapper<>(); //and() 查询last_name等于皮皮虾b 和 gender等于1 的数据 (不使用and() 默认就是and()) andWrapper.eq("last_name", "皮皮虾b").eq("gender", 1); List<Employee> andList = employeeService.list(andWrapper ); System.out.println(and...
使用mybatisPlus实现分页查询,很实用的一个东西。 首先配置好Config文件 @Configuration public class MybatisPlusConfig { @Bean public MybatisPlusInterceptor paginationInterceptor(){ MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); PaginationInnerInterceptor paginationInnerInterceptor = new Paginati...
- 创建一个QueryWrapper对象,其中提供了很多的查询方法,用其设置查询条件,然后使用userMapper调用selectList方法即可以完成基本的条件查询 下面再举两个例子来说明 //2.创建日期为2019年2月14日并且直属上级为名字为王姓 //date_format(create_time,'%Y-%m-%d')='2019-02-14' and manager_id in (select id fr...
1 简单查询 对于简单的查询,例如根据某一个字段或ID进行查询,使用 MyBatisPlus 可以直接进行。 1.1 根据ID查询 代码语言:txt 复制 @Test public void getUser(){ User user = userMapper.selectById(1); System.out.println(user); } 效果等同于如下SQL语句 ...
WRAPPER) Wrapper<T> queryWrapper); // 查询所有记录(但只保存第一个字段的值) <E extends IPage<T>> E selectPage(E page, @Param(Constants.WRAPPER) Wrapper<T> queryWrapper); // 查询所有记录(返回 entity 集合),分页 <E extends IPage<Map<String, Object>>> E selectMapsPage(E page, @Param(...
03.《MyBatis-Plus快速实现增删改 [MyBatis-Plus系列]-第484篇》 一、普通查询 先来看下普通查询(未分页),这种查询很简单,就是查询条件如何进行设置,常规的查询条件就是等于,大于,小于,模糊查询之类的。 2.1 查询所有数据 没有条件的查询,使用的方法是selectList: @Test public void testSelectAll() { List<...
三、分页查询 1、注册PaginationInterceptor分页插件 @ConfigurationpublicclassMybatisPlusConfiguration{@BeanpublicPaginationInterceptorpaginationInterceptor(){// paginationInterceptor.setLimit(你的最大单页限制数量,默认 500 条,小于 0 如 -1 不returnnewPaginationInterceptor();}} ...
SELECT id,name,password,age,tel FROM user WHERE (age < ? AND age > ?) 也是迅速查出来了结果 3.2或的情况 场景二:查询数据库表中,年龄小于3或年龄大于8的数据 @SpringBootTest class Mybatisplus{ @Autowired private UserDao userDao; @Test void testGetAll(){ LambdaQueryWrapper<User> lqw = new...