分布式电商项目(04)--商品列表查询及分页
2018-11-14 23:16
666 查看
前言:前面写了后天管理系统工程搭建以及框架的整合测试,今天写一下商品列表的分页查询
1 需求分析
前台使用easyui的分页工具,后台则使用mybatis分页插件pagehelper
如上图所示,打开后台首页,点击查询商品,按下F12,可以看到easyui的分页界面会向controller发送两个数据page:1,rows:30
controller通过service层以及dao层查询到数据之后也需要将数据封装成easyui需要的格式,而easyui需要的数据格式如下
{ total:"2", rows:[ {"id":"1","name":"username1"}, {"id":"2","name":"username2"} ] }
对应现在的场景就是将数据封装成total:商品总数,rows:商品信息列表的格式
2 具体实现
2.1 封装通用的分页工具类
由于分页在后面肯定还会用到,现在在common工程下写一个easyui分页的工具类,具体的代码如下:
public class EUDataGridResult { private long total; private List<?> rows; public long getTotal() { return total; } public void setTotal(long total) { this.total = total; } public List<?> getRows() { return rows; } public void setRows(List<?> rows) { this.rows = rows; } }
2.2 编写接口及其实现类
在service工程下编写service类及其实现类
ItemService的代码如下:
public interface ItemService { EUDataGridResult getItemList(Integer page, Integer rows); }
ItemServiceImpl的代码如下:
@Service public class ItemServiceImpl implements ItemService { @Autowired private TbItemMapper itemMapper; /** * 商品列表查询 * @param page * @param rows * @return */ @Override public EUDataGridResult getItemList(Integer page, Integer rows) { TbItemExample example = new TbItemExample(); PageHelper.startPage(page,rows); List<TbItem> list = itemMapper.selectByExample(example); EUDataGridResult result = new EUDataGridResult(); result.setRows(list); PageInfo<TbItem> info = new PageInfo<>(list); result.setTotal(info.getTotal()); return result; } }
2.3 编写Controller
ItemController的代码如下:
package com.taotao.controller; import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import com.taotao.pojo.EUDataGridResult; import com.taotao.pojo.TaotaoResult; import com.taotao.pojo.TbItem; import com.taotao.service.ItemService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; import java.util.List; @Controller public class ItemController { @Autowired private ItemService itemService; /** * 商品列表查询 * @param page * @param rows * @return */ @RequestMapping("/item/list") @ResponseBody public EUDataGridResult getItemList(Integer page, Integer rows ){ EUDataGridResult result = itemService.getItemList(page, rows); return result; } }
此处要注意,RequestMapping中的值一定要与jsp页面中的请求的值是一致的
3 测试
运行项目,点击查询商品可以查询出商品列表即为成功,即出现如下图所示的界面:
4 相关文件
下面提供一些相关的资源下载,包括后台管理系统的静态资源,博主使用的本地仓库等
链接:https://pan.baidu.com/s/1mWDQznk0N5um_YMB7Greiw
提取码:1gh3
相关文章推荐
- 框架 day74 涛涛商城项目整合ssm,分页插件pagehelper,商品列表查询
- 008商城项目:商品列表查询-查出商品并且分页
- 第三章-电商项目-优化评论分页查询
- 007商城项目:商品列表查询-需求分析,以及Spinmvc的访问知识
- 商城项目中商品的分页查询
- SSH框架网上商城项目第5战之商品类别级联查询和分页功能
- JAVAEE——BOS物流项目04:学习计划、datagrid、分页查询、批量删除、修改功能
- 商城项目实战14:MyBatis分页插件(PageHelper)的使用以及商品列表展示
- mybatis分页插件的使用(电商项目前端动态查询排序)
- 【定区管理功能】定区列表分页条件查询
- 商品的CRUD,分页查询
- MongoDB:mongodb在项目开发时的安全验证、分页查询操作
- java大型分布式电商项目实战高并发集群分布式系统架构
- Spark日志分析项目Demo(7)--临时表查询,各区域top3热门商品统计
- (B2C网上商城)分布式大型电商实战项目
- 分布式大型电商实战项目搭建教程
- 手把手教你写电商爬虫-第二课 实战尚妆网分页商品采集爬虫
- MongoDB:mongodb在项目开发时的安全验证、分页查询操作
- 【SSH网上商城项目实战11】查询和删除商品功能的实现