@RestController
//在方法上就不需要使用@ResponseBody了
@PostMapping("/goods/condition/phelps")
public Object conditionalPhelps(GoodsEntity goodsEntity,String pageNo,String pageSize){
List<GoodsEntity> goodsEntityList=new ArrayList<>();
//编写分页代码
PageHelper.startPage(goodsEntity.getPageNo(),goodsEntity.getPageSize());
PageInfo<GoodsEntity> pageInfo=null;
//创建实体类对象
//此处返回的list实现类不再是ArrayList,而是PageHelper提供的Page对象
goodsEntityList=goodsService.selectGoodsByConditionForPage(goodsEntity);
//分页代码
pageInfo=new PageInfo<GoodsEntity>(goodsEntityList,goodsEntity.getPageSize());
return ResultBuilder.buildSuccess(ResultJson.CODE_OK,pageInfo);
}
需要建立一个实体类继承GoodsEntity并且在你的实体类中创建pageNo,pageSize参数
如下:
public class EopGoodsEntity extends GoodsEntity{
private Integer pageSize;
private Integer pageNo;
}
//将上面的代码修改为:
@PostMapping("/goods/condition/phelps")
public Object conditionalPhelps(@RequestBody EopGoodsEntity eopGoodsEntity){
List<GoodsEntity> goodsEntityList=new ArrayList<>();
//编写分页代码
PageHelper.startPage(eopGoodsEntity.getPageNo(),eopGoodsEntity.getPageSize());
PageInfo<GoodsEntity> pageInfo=null;
//创建实体类对象
//此处返回的list实现类不再是ArrayList,而是PageHelper提供的Page对象
goodsEntityList=goodsService.selectGoodsByConditionForPage(eopGoodsEntity);
//分页代码
pageInfo=new PageInfo<GoodsEntity>(goodsEntityList,eopGoodsEntity.getPageSize());
return ResultBuilder.buildSuccess(ResultJson.CODE_OK,pageInfo);
}