从零到企业级SSM电商项目实战教程(二十八)后台商品列表动态分页功能开发

ProductManageController.java

/*
 * @Description: 后台商品列表
 *
 * @auther: Geekerstar(jikewenku.com)
 * @date: 2018/6/23 15:46
 * @param: [session, pageNum, pageSize]
 * @return: com.mmall.common.ServerResponse
 */
@RequestMapping("list.do")
@ResponseBody
public ServerResponse getList(HttpSession session, @RequestParam(value = "pageNum",defaultValue = "1") int pageNum, @RequestParam(value = "pageSize",defaultValue = "10") int pageSize){
    User user = (User)session.getAttribute(Const.CURRENT_USER);
    if(user == null){
        return ServerResponse.createByErrorCodeMessage(ResponseCode.NEED_LOGIN.getCode(),"用户未登录,请登录管理员");

    }
    if(iUserService.checkAdminRole(user).isSuccess()){
        //填充业务
        return iProductService.getProductList(pageNum,pageSize);
    }else{
        return ServerResponse.createByErrorMessage("无权限操作");
    }
}

IProductService.java

ServerResponse getProductList(int pageNum, int pageSize);

ProductServiceImpl.java

public ServerResponse getProductList(int pageNum,int pageSize){
    //startPage--start
    //填充自己的sql查询逻辑
    //pageHelper-收尾
    PageHelper.startPage(pageNum,pageSize);
    List productList = productMapper.selectList();

    List productListVoList = Lists.newArrayList();
    for(Product productItem : productList){
        ProductListVo productListVo = assembleProductListVo(productItem);
        productListVoList.add(productListVo);
    }
    PageInfo pageResult = new PageInfo(productList);
    pageResult.setList(productListVoList);
    return ServerResponse.createBySuccess(pageResult);
}

private ProductListVo assembleProductListVo(Product product){
    ProductListVo productListVo = new ProductListVo();
    productListVo.setId(product.getId());
    productListVo.setName(product.getName());
    productListVo.setCategoryId(product.getCategoryId());
    productListVo.setImageHost(PropertiesUtil.getProperty("ftp.server.http.prefix","http://img.happymmall.com/"));
    productListVo.setMainImage(product.getMainImage());
    productListVo.setPrice(product.getPrice());
    productListVo.setSubtitle(product.getSubtitle());
    productListVo.setStatus(product.getStatus());
    return productListVo;
}

ProductListVo.java

vo 包下新建 ProductListVo.java

package com.mmall.vo;

import java.math.BigDecimal;

/**
 * @Author: Geekerstar(jikewenku.com)
 * @Date: 2018/6/23 15:41
 * @Description:
 */
public class ProductListVo {
    private Integer id;
    private Integer categoryId;

    private String name;
    private String subtitle;
    private String mainImage;
    private BigDecimal price;

    private Integer status;

    private String imageHost;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getCategoryId() {
        return categoryId;
    }

    public void setCategoryId(Integer categoryId) {
        this.categoryId = categoryId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSubtitle() {
        return subtitle;
    }

    public void setSubtitle(String subtitle) {
        this.subtitle = subtitle;
    }

    public String getMainImage() {
        return mainImage;
    }

    public void setMainImage(String mainImage) {
        this.mainImage = mainImage;
    }

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getImageHost() {
        return imageHost;
    }

    public void setImageHost(String imageHost) {
        this.imageHost = imageHost;
    }
}

ProductMapper.java

List selectList();

ProductMapper.xml


本站所有文章均由网友分享,仅用于参考学习用,请勿直接转载,如有侵权,请联系网站客服删除相关文章。若由于商用引起版权纠纷,一切责任均由使用者承担
极客文库 » 从零到企业级SSM电商项目实战教程(二十八)后台商品列表动态分页功能开发

Leave a Reply

欢迎加入「极客文库」,成为原创作者从这里开始!

立即加入 了解更多