springboot+mybatis+layui二手网java mysql二手商城源码

【287】springboot+mybatis+layui二手网java mysql二手商城源码

技术:
 后端:springboot mybatis springmvc
前端: layUI  html  jquery  ajax

管理员账号密码: admin  admin

package com.hn.secondhand.control.admin;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hn.secondhand.dto.GoodsInfoDTO;
import com.hn.secondhand.po.Goods;
import com.hn.secondhand.po.Sort;
import com.hn.secondhand.po.User;
import com.hn.secondhand.service.GoodsService;
import com.hn.secondhand.service.SortService;
import com.hn.secondhand.service.UserService;
import com.hn.secondhand.tool.Result;
import com.hn.secondhand.tool.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;

/**
 * Created by hn on 2021-4-8.
 */
@Controller("admin/GoodsController")
@RequestMapping("admin")
public class GoodsController {

    @Resource
    private GoodsService goodsService;

    @Resource
    private SortService sortService;

    @Resource
    private UserService userService;

    // 跳转到闲置物品列表页面
    @GetMapping("/goods")
    public String goGoods() {
        return "/admin/goods";
    }

    // 异步获取闲置物品分页数据
    @PostMapping("/goods")
    @ResponseBody
    public Result goods(Integer pageNum, Integer pageSize, String display) {
        // 设置分页规则
        PageHelper.startPage(pageNum, pageSize);

        HashMap<String, Object> searchMap = new HashMap<>();
        if (!StringUtils.isBlank(display)) {
            searchMap.put("display", display);
        }
        Page<Goods> goodsPage = goodsService.pageWith(searchMap);
        Page<GoodsInfoDTO> goodsList = new Page<>();
        for (Goods goods : goodsPage) {
            GoodsInfoDTO goodsInfoDTO = new GoodsInfoDTO();
            goodsInfoDTO.setId(goods.getId());
            Sort sort = sortService.getSortById(goods.getSort());
            goodsInfoDTO.setSortName(sort.getName());
            goodsInfoDTO.setTitle(goods.getTitle());
            goodsInfoDTO.setPrice(goods.getPrice());
            User user = userService.getUserById(goods.getUid());
            goodsInfoDTO.setUsername(user.getUsername());
            goodsInfoDTO.setDatetime(goods.getGmt_modified());
            goodsInfoDTO.setContact(goods.getContact());
            goodsInfoDTO.setInfo(goods.getInfo());
            goodsInfoDTO.setImage(goods.getImage());
            goodsInfoDTO.setDisplay(goods.getDisplay());
            goodsList.add(goodsInfoDTO);
        }
        goodsList.setPageNum(goodsPage.getPageNum());
        goodsList.setPageSize(goodsPage.getPageSize());
        goodsList.setStartRow(goodsPage.getStartRow());
        goodsList.setEndRow(goodsPage.getEndRow());
        goodsList.setTotal(goodsPage.getTotal());
        goodsList.setPages(goodsPage.getPages());
        goodsList.setReasonable(goodsPage.getReasonable());

        return Result.success("用户列表", goodsList.toPageInfo());
    }

    // 更新闲置物品状态
    @PostMapping("/goods/update")
    @ResponseBody
    public Result update(Goods goods) {
        int result = goodsService.update(goods);
        if (result != 1) {
            return Result.fail("系统异常");
        }
        return Result.success("修改成功");
    }

    // 根据 id 删除指定闲置物品
    @PostMapping("/goods/delete")
    @ResponseBody
    public Result delete(Integer id) {
        int result = goodsService.delete(id);
        if (result != 1) {
            return Result.fail("系统异常");
        }
        return Result.success("删除成功");
    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值