由于使用逆向工程,生成出来的代码,已经带有分页功能,但是明明查询第一页,却查出了整张表的所有数据。
Controller层代码
@IgnoreAuth
@RequestMapping("/list")
public R list(@RequestParam Map<String, Object> params){
PageUtils page = categoryService.queryPage(params);
return R.ok().put("page", page);
}
service层代码
@Service("categoryService")
public class CategoryServiceImpl extends ServiceImpl<CategoryDao, Category> implements CategoryService {
@Override
public PageUtils queryPage(Map<String, Object> params) {
IPage<Category> page = this.page(
new Query<Category>().getPage(params),
new QueryWrapper<Category>()
);
return new PageUtils(page);
}
}
解决办法: 添加一个分页配置类
package com.ithuang.school.learnschema.config;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
@ConditionalOnClass(value