SSM框架MySQL使用Mybatis插件PageHelper分页失败--出坑指南!

最近搭建SSM框架进行小型项目玩下,
框架搭建完成 最基本增删改查已全部实现,
在查询过程中一次查询大量数据需要分页,于是想到MySQL的limit分页,参数传递需要自己去写,以后有好多这样的东西要去写 想想都头大
网络是个好东西 搜索之后PageHelper很诱人
于是进行各种配置,maven引入(很奇怪,之前引入的不是spring-boot一直失败):

<dependency>
   <groupId>com.github.pagehelper</groupId>
  		<artifactId>pagehelper-spring-boot-autoconfigure</artifactId>
    <version>1.2.7</version>
</dependency>

然后对项目进行Maven => update project

下面是查询代码:

@RequestMapping(value = "/allSals/{salsType}/{pageNum}", method = {RequestMethod.GET })
@ResponseBody
public PageInfo<SalsAddressInfo> allSals(HttpServletRequest request, 
		@PathVariable("salsType") String salsType,@PathVariable("pageNum") int pageNum, 
		HttpServletResponse response)throws IOException {
	Map<String, Object> params=new HashMap<String, Object>();
	params.put("salsType",salsType);
	PageHelper.startPage(pageNum, 30);
	List<SalsAddressInfo> infos=salsAddressInfoMapper.allsalas(params);
	PageInfo<SalsAddressInfo> pageInfo = new PageInfo<SalsAddressInfo>(infos);
    return pageInfo;
}

本地启动验证总是分页失败,查出来的数据未分页
甚是无奈!经过debug调试 发现所传参数pageNum是0,竟然是0!
经过这次教训 告诫自己以后敲代码一定要胆大 心细 再心细!!!

发布了35 篇原创文章 · 获赞 6 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/GJ454221763/article/details/92388458