• 极客专栏正式上线!欢迎访问 https://www.jikewenku.com/topic.html
  • 极客专栏正式上线!欢迎访问 https://www.jikewenku.com/topic.html

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

项目实战 Geekerstar 10个月前 (06-23) 601次浏览 已收录 0个评论 扫描二维码
文章目录[隐藏]

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<PageInfo> getProductList(int pageNum, int pageSize);

ProductServiceImpl.java

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

    List<ProductListVo> 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<Product> selectList();

ProductMapper.xml

<select id="selectList" resultMap="BaseResultMap">
  SELECT 
  <include refid="Base_Column_list"/>
  FROM mmall_product
  ORDER BY id asc
</select>

喜欢 (0)
[247507792@qq.com]
分享 (0)
Geekerstar
关于作者:
本站技术支持

您必须 登录 才能发表评论!

  • 精品技术教程
  • 编程资源分享
  • 问答交流社区
  • 极客文库知识库

客服QQ


QQ:2248886839


工作时间:09:00-23:00