springboot+mybatisplus分页实现
分页
public Page recommendUsers(long pageSize, long pageNum,HttpServletRequest request) {
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
Page<User> page = userService.page(new Page<>(pageNum,pageSize), queryWrapper);
return page;
}
配置类
package com.bo.partner.config;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* @author: bo
* @date: 2022/9/10
* @description:
*/
@Configuration
@MapperScan("com.bo.partner.mapper")
public class MybatisPlusConfig {
/**
* 新的分页插件,一缓和二缓遵循mybatis的规则,需要设置 MybatisConfiguration#useDeprecatedExecutor = false 避免缓存出现问题(该属性会在旧插件移除后一同移除)
*/
@Bean
public MybatisPlusInterceptor mybatisPlusInterceptor() {
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
return interceptor;
}
}
我是mysql的数据库
但是前端取不到数据了,mybatisplus分页封装了一层
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-HmaECD6z-1662947320422)(C:/Users/1/AppData/Roaming/Typora/typora-user-images/image-20220910202508866.png)]
取数据时候加个.records
就可以取到了