一、实现目标
点击商品列表,分页展示所有商品
二、前端分析
需要编写对应的controller,映射到/rest/item
三、创建TaoResult
package com.taotao.common;
import java.io.Serializable;
import java.util.List;
public class TaoResult<T> implements Serializable{
private long total;
private List<T> rows;
public long getTotal() {
return total;
}
public void setTotal(long total) {
this.total = total;
}
public List<T> getRows() {
return rows;
}
public void setRows(List<T> rows) {
this.rows = rows;
}
}
四、Service实现
1.在taotao-manager-interface编写接口
2.在taotao-manager-service实现方法
@Override
public TaoResult<Item> queryItemList(Integer page, Integer rows) {
// 设置分页数据
PageHelper.startPage(page, rows);
List<Item> list = super.queryListByWhere(null);
// 获取分页的详细数据
PageInfo<Item> pageInfo = new PageInfo<>(list);
// 封装返回对象
TaoResult<Item> taoResult = new TaoResult<>();
taoResult.setTotal(pageInfo.getTotal());
taoResult.setRows(list);
return taoResult;
}
五、实现controller
在ItemController中直接添加展示商品方法
@RequestMapping(method = RequestMethod.GET)
@ResponseBody
public TaoResult<Item> queryItemList(@RequestParam(value = "page", defaultValue = "1") Integer page,
@RequestParam(value = "rows", defaultValue = "30") Integer rows) {
TaoResult<Item> easyUIResult = this.itemService.queryItemList(page, rows);
return easyUIResult;
}
六、测试
成功!!!