开始
前端代码
编写controller之前先来看下前端的代码
后端controller
@Api(value = "用户中心我的订单", tags = {"用户中心我的订单相关接口"})
@RestController
@RequestMapping("/myorders")
public class MyOrdersController {
@Autowired
private MyOrderService myOrderService;
}
复制一个写过的分页的方法 过来修改
复制。ItemsController
修改如下
这里修改下变量
默认的分页就是10条
之前写过的分页的变量名也要修改为最新的
分页
@Api(value = "用户中心我的订单", tags = {"用户中心我的订单相关接口"})
@RestController
@RequestMapping("/myorders")
public class MyOrdersController extends BaseController {
@Autowired
private MyOrderService myOrderService;
@ApiOperation(value = "搜索商品列表",notes = "搜索商品列表",httpMethod ="GET" )
@PostMapping("/query")
public IMOOCJSONResult comments(
@ApiParam(name = "userId",value = "用户id",required = true)
@RequestParam String userId,
@ApiParam(name = "orderStatus",value = "订单状态",required = false)
@RequestParam Integer orderStatus,
@ApiParam(name = "page",value = "查询下一页的第几页",required = false)
@RequestParam Integer page,
@ApiParam(name = "pageSize",value = "分页的每一页显示的条数",required = false)
@RequestParam Integer pageSize){
if(StringUtils.isBlank(userId)){
return IMOOCJSONResult.errorMsg(null);
}
if(page==null){
page=1;
}
if(pageSize==null){
pageSize=COMMON_PAGE_SIZE;
}
PagedGridResult grid = myOrderService.queryMyOrders(userId,
orderStatus,
page,
pageSize);
return IMOOCJSONResult.ok(grid);
}
}
修复一个bug
之前在写MyOrderServiceImpl的时候,没有加@Service的注解。现在加上。要不然项目启动不了
测试
maven install
重启服务
刷新页面,没数据
后端报错
这里用不到这个字段,先删掉
刷新有数据了
分页也有效果