基于springboot数码电脑商城支付宝沙箱支付源码含论文

【469】基于springboot数码电脑商城支付宝沙箱支付源码含论文


 开发工具:idea 或eclipse
 数据库mysql5.7+
 数据库链接工具:navcat,小海豚等
  技术: springboot  mybatis   html  ajax

在查阅了许多网站开发的相关资料的基础上,提出了基于Java技术,采用B/S构建结构,选用Spring Boot框架,Mybatis框架,运用Ajax技术,UML技术和MySQL数据库来开发一个电脑商城网站,不同于市面上的京东、淘宝等购物网站,而是针对电脑购物的新型电子购物商城,包含管理员、用户和商家三个模块实现了商城的基本功能,使得电脑商品的交易更加方便,有效,成本更低,将成为电脑商品销售的崭新模式,具有一定的实际意义和推广价值。

关键词:电脑商城    Java    Spring Boot框架    MySQL

系统部署说明:

系统开发环境:
(1)操作系统:Windows10
(2)数据库:MySQL 5.7.1、Navicat for MySQL
(3)Web服务器:Tomcat 9.0
(4)开发技术和工具:IntelliJ IDEA 2019.3 x64、Spring Boot、MyBatis
系统部署:
  (1)安装IntelliJ IDEA。
(2)安装MySQL 5.7.1、Navicat for MySQL,创建数据库,并运行数据库文件 computer_shop.sql。
  (3)用IntelliJ IDEA 2019.3 x64打开项目,在application.yaml文件中修改连接数据库的账号和密码。

package com.springboot.project.controller;


import com.alibaba.fastjson.JSONObject;
import com.springboot.project.mapper.StoreMapper;
import com.springboot.project.pojo.*;
import com.springboot.project.service.*;
import com.springboot.project.tools.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@Controller
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    private GoodsService goodsService;
    @Autowired
    private EvaluateService evaluateService;
    @Autowired
    private AddressService addressService;
    @Autowired
    private GoodsTypeService goodsTypeService;
    @Autowired
    private OrderService orderService;
    @Autowired
    private UserService userService;
    @Autowired
    private BrandService brandService;
    @Autowired
    private StoreMapper storeMapper;
    @Autowired
    private StoreService storeService;
    @Value("${fileaddress}")
    private String fileaddress;
    /*获得全部商品*/
    @RequestMapping("/getAllGoods")
    public String getAllGoods(Model model) {
        List<Goods> allGoodsList = goodsService.getAllGoods();
        model.addAttribute("allGoodsList", allGoodsList);
        return "/goodsList";
    }

    /*模糊查询*/
    @RequestMapping("/getGoodsByLikeName/{goodsName}")
    public String getGoodsByLikeName(@PathVariable String goodsName,Model model){
        List<Goods> allGoodsList = goodsService.getGoodsByLikeName(goodsName);
        model.addAttribute("allGoodsList",allGoodsList);
        return "/goodsList";
    }

    /*根据goods_Id获得商品*/
    @RequestMapping("/getGoodsById/{goodsId}")
    public String getGoodsById(@PathVariable int goodsId, Model model)  throws ParseException {
        Goods goods = goodsService.getGoodsById(goodsId);
        if (goods==null){
            return "/error";
        }
        Store store = storeService.getByStoreId(goods.getGoodsStore());
        GoodsStore goodsStore = new GoodsStore();
        goodsStore.setGoodsId(goods.getGoodsId());
        goodsStore.setGoodsName(goods.getGoodsName());
        goodsStore.setGoodsAttr(goods.getGoodsAttr());
        goodsStore.setGoodsBrand(goods.getGoodsBrand());
        goodsStore.setGoodsDesc(goods.getGoodsDesc());
        goodsStore.setGoodsNums(goods.getGoodsNums());
        goodsStore.setGoodsStore(goods.getGoodsStore());
        goodsStore.setGoodsType(goods.getGoodsType());
        goodsStore.setGoodsImg(goods.getGoodsImg());
        goodsStore.setGoodsSales(goods.getGoodsSales());
        goodsStore.setGoodsPrice(goods.getGoodsPrice());
        goodsStore.setStoreName(store.getStoreName());
        List<Evaluate> evaluateList = evaluateService.getEvaByGoodsId(goodsId);

        List<Evaluate3> evaluate3List = new ArrayList<>();
        for (Evaluate evaluate : evaluateList) {
            User user = userService.selectUserByUserId(evaluate.getEvaUser());
            Evaluate3 evaluate3 = new Evaluate3();
            evaluate3.setEvaId(evaluate.getEvaId());
            evaluate3.setEvaUser(evaluate.getEvaUser());
            evaluate3.setEvaGoods(evaluate.getEvaGoods());
            evaluate3.setEvaContent(evaluate.getEvaContent());
            evaluate3.setEvaLevel(evaluate.getEvaLevel());

            SimpleDateFormat sf1 = new SimpleDateFormat("EEE MMM dd hh:mm:ss z yyyy", Locale.ENGLISH);
            Date date = sf1.parse(String.valueOf(evaluate.getEvaDate()));
            SimpleDateFormat sf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            evaluate3.setEvaDate(sf2.format(date));
            evaluate3.setEvaStore(evaluate.getEvaStore());
            evaluate3.setEvaState(evaluate.getEvaState());
            evaluate3.setUser_Img(user.getUserImg());
            evaluate3List.add(evaluate3);
        }

        int typeId = goods.getGoodsType();
        model.addAttribute("goods", goodsStore);
        model.addAttribute("typeId", typeId);
        model.addAttribute("evaluateList", evaluate3List);
        return "/goodsBuy";
    }

    /*订单详情页*/
    @RequestMapping("/getGoodsByIdBuy/{goodsId}/{num}")
    public String getGoodsByIdBuy(@PathVariable int goodsId,@PathVariable int num, Model model, HttpServletRequest request) {
        HttpSession session = request.getSession();
        int userId = (int) session.getAttribute("userId");
        Goods goods = goodsService.getGoodsById(goodsId);
        List<Address> address = addressService.getAddrByUserId(userId);
        Address address1 = addressService.getAddrByUserIdByDefault(userId);
        BigDecimal price = goods.getGoodsPrice();
        int price2 = price.intValue() * num;
        BigDecimal price3 = new BigDecimal(price2);
        goods.setGoodsPrice(price3);
        model.addAttribute("addressList",address);
        model.addAttribute("address1",address1);
        model.addAttribute("goods",goods);
        model.addAttribute("goodsId",goodsId);
        model.addAttribute("num",num);
        return "/order";
    }

    /*购物车页面*/
    @RequestMapping("/cart")
    public String cart(Model model,HttpSession session){

        int userId = (int) session.getAttribute("userId");
        List<Cart> cartList = goodsService.getCartByUserId(userId);

        List<Goods> goodsList = new ArrayList<>();
        for (int i=0;i<cartList.size();i++){
            Goods goods1 = goodsService.getGoodsById(cartList.get(i).getCartGoods());
            goodsList.add(goods1);
        }
        List<GoodsType> goodsTypes = new ArrayList<>();
        for (int i=0;i<goodsList.size();i++){
            GoodsType goodsType = goodsTypeService.getTypeByTypeId(goodsList.get(i).getGoodsType());
            goodsTypes.add(goodsType);
        }
        List<CartGoods2> cartGoodsList = new ArrayList<>();
        for (int i=0;i<cartList.size();i++){
            CartGoods2 cartGoods = new CartGoods2();
            cartGoods.setCartId(cartList.get(i).getCartId());
            cartGoods.setCartGoods(cartList.get(i).getCartGoods());
            cartGoods.setCartNum(cartList.get(i).getCartNum());
            cartGoods.setCartPrice(cartList.get(i).getCartPrice());
            cartGoods.setCartUser(cartList.get(i).getCartUser());
            cartGoods.setGoodsId(goodsList.get(i).getGoodsId());
            cartGoods.setGoodsName(goodsList.get(i).getGoodsName());
            cartGoods.setGoodsNums(goodsList.get(i).getGoodsNums());
            cartGoods.setGoodsAttr(goodsList.get(i).getGoodsAttr());
            cartGoods.setGoodsImg(goodsList.get(i).getGoodsImg());
            cartGoods.setTypeId(goodsTypes.get(i).getTypeId());
            cartGoods.setTypeName(goodsTypes.get(i).getTypeName());
            BigDecimal num = new BigDecimal( cartList.get(i).getCartNum());
            BigDecimal price = cartList.get(i).getCartPrice();
            BigDecimal allPrice = price.multiply(num);
            cartGoods.setAllcartNum(allPrice);
            cartGoodsList.add(cartGoods);
        }

        model.addAttribute("cartGoodsList",cartGoodsList);
        return "/cart";
    }


    /*获取全部商品信息 分页*/
    @RequestMapping("/getAllGoodsByStoreId")
    @ResponseBody
    public JSONObject getAllGoodsByStoreId(int page, int limit, String keyWord, HttpSession session) {
        int userId = (int) session.getAttribute("userId");
        PageBean pageBean = new PageBean();
        pageBean.setPage(page);
        pageBean.setLimit(limit);
        PageBean<GoodsIntact> pBean = goodsService.getPageBean(pageBean.getPage(), pageBean.getLimit(), keyWord,userId);
        JSONObject jsObj = new JSONObject();
        jsObj.put("msg", "");
        jsObj.put("code", 0);
        jsObj.put("count", pBean.getTotalRecs());
        jsObj.put("data", pBean.getJsArr());
        return jsObj;
    }


    /*获取全部商品信息 分页*/
    @RequestMapping("/getAllGoodsByStoreIdAndGoodId")
    @ResponseBody
    public JSONObject getAllGoodsByStoreIdAndGoodId(int page, int limit, String keyWord,String search, HttpSession session) {
        int userId = (int) session.getAttribute("userId");
        PageBean pageBean = new PageBean();
        pageBean.setPage(page);
        pageBean.setLimit(limit);
        PageBean<GoodsIntact> pBean = goodsService.getPageBean2(pageBean.getPage(), pageBean.getLimit(), keyWord,search,userId);
        JSONObject jsObj = new JSONObject();
        jsObj.put("msg", "");
        jsObj.put("code", 0);
        jsObj.put("count", pBean.getTotalRecs());
        jsObj.put("data", pBean.getJsArr());
        return jsObj;
    }


    /*获取全部订单信息分页*/
    @RequestMapping("/getAllOrdersByStoreId")
    @ResponseBody
    public JSONObject getAllGoodsByStoreId(Integer page, Integer limit, String keyWord, HttpSession session) {
        int userId = (int) session.getAttribute("userId");

        PageBean pageBean = new PageBean();
        pageBean.setPage(page);
        pageBean.setLimit(limit);
        PageBean<orderGoods2> pBean = orderService.getPageBean(pageBean.getPage(), pageBean.getLimit(), keyWord,userId);
        JSONObject jsObj = new JSONObject();
        jsObj.put("msg", "");
        jsObj.put("code", 0);
        jsObj.put("count", pBean.getTotalRecs());
        jsObj.put("data", pBean.getJsArr());
        return jsObj;
    }


    /*获取订单信息 搜索 分页*/
    @RequestMapping("/getAllOrdersByStoreId2")
    @ResponseBody
    public JSONObject getAllGoodsByStoreId2(Integer page, Integer limit, String keyWord,String search, HttpSession session) {
        int userId = (int) session.getAttribute("userId");
        PageBean pageBean = new PageBean();
        pageBean.setPage(page);
        pageBean.setLimit(limit);
        PageBean<orderGoods2> pBean = orderService.getPageBean2(pageBean.getPage(), pageBean.getLimit(), keyWord,search,userId);
        JSONObject jsObj = new JSONObject();
        jsObj.put("msg", "");
        jsObj.put("code", 0);
        jsObj.put("count", pBean.getTotalRecs());
        jsObj.put("data", pBean.getJsArr());
        return jsObj;
    }


    /*获取全部评论信息 分页*/
    @RequestMapping("/getAllEvaluateByStoreId")
    @ResponseBody
    public JSONObject getAllEvaluateByStoreId(Integer page, Integer limit, String keyWord, HttpSession session) {

        int userId = (int) session.getAttribute("userId");

        PageBean pageBean = new PageBean();
        pageBean.setPage(page);
        pageBean.setLimit(limit);
        PageBean<Evaluate2> pBean = evaluateService.getPageBean(pageBean.getPage(), pageBean.getLimit(), keyWord,userId);
        JSONObject jsObj = new JSONObject();
        jsObj.put("msg", "");
        jsObj.put("code", 0);
        jsObj.put("count", pBean.getTotalRecs());
        jsObj.put("data", pBean.getJsArr());
        return jsObj;
    }

    /*通过商品获取全部评论信*/
    @RequestMapping("/getAllCommByGoodsId")
    @ResponseBody
    public JSONObject getAllByGoodsId(Integer page, Integer limit, String keyWord, String search,HttpSession session) {
        System.out.println(search);
        int userId = (int) session.getAttribute("userId");
        PageBean pageBean = new PageBean();
        pageBean.setPage(page);
        pageBean.setLimit(limit);
        PageBean<Evaluate2> pBean = evaluateService.getPageBean2(pageBean.getPage(), pageBean.getLimit(), Integer.parseInt(search),userId);
        JSONObject jsObj = new JSONObject();
        jsObj.put("msg", "");
        jsObj.put("code", 0);
        jsObj.put("count", pBean.getTotalRecs());
        jsObj.put("data", pBean.getJsArr());
        return jsObj;
    }

    /*下架商品*/
    @RequestMapping("/deleteGood")
    @ResponseBody
    public String deleteGood(@RequestParam(value = "goodsId",required = true)int goodsId){

        int i =goodsService.deleteGoodsByGoodsId(goodsId);

        if(i == 1){
            return "success";
        }else {
            return "flag";
        }
    }
    /*上架商品*/
    @RequestMapping("/renewGoods/{goodsId}")
    @ResponseBody
    public String renewGoods(@PathVariable int goodsId){
        int rs = goodsService.renewGoods(goodsId);
        if (rs>0){
            return "success";
        }else {
            return "fail";
        }
    }

    /*发货*/
    @RequestMapping("/updateGoodsByDelivery")
    @ResponseBody
    public  String updateGoodsByDelivery(@RequestParam(value = "id",required = true)Long id){

        int i = goodsService.updateGoodsByDelivery(id);
        if(i == 1){
            return "success";
        }else {
            return "flag";
        }
    }
    /*确认收货*/
    @RequestMapping("/getGoodsByIdReceiving")
    @ResponseBody
    public String getGoodsByIdReceiving(@RequestParam(value = "orderId",required = true)Long id){

        int i = goodsService.getGoodsByIdReceiving(id);

        if(i == 1){
            return "success";
        }else {
            return "flag";
        }
    }

    @RequestMapping("/getAllBrand")
    @ResponseBody
    public List<Brand> getAllBrand(){
        List<Brand> brandList = brandService.getAllBrand();
        return brandList;
    }
    @RequestMapping("/getAllGoodsType")
    @ResponseBody
    public List<GoodsType> getAllGoodsType(){
        List<GoodsType> goodsTypeList = goodsTypeService.getAllGoodsType();
        return goodsTypeList;
    }
    @RequestMapping("/getGoodsByBrand/{brandId}")
    public String getGoodsByBrand(@PathVariable int brandId,Model model){
        List<Goods> allGoodsList = goodsService.getGoodsByBrand(brandId);
        model.addAttribute("allGoodsList", allGoodsList);
        return "/goodsList";
    }


    @RequestMapping("/getGoodsByType/{typeId}")
    public String getGoodsByType(@PathVariable int typeId,Model model){
        List<Goods> allGoodsList = goodsService.getGoodsByType(typeId);
        model.addAttribute("allGoodsList", allGoodsList);
        return "/goodsList";
    }

    @RequestMapping("/toAddGoods")
    public String toAddGoods(){
        return "/admin/addGoods";
    }

    @RequestMapping(value = "/upload")
    @ResponseBody
    public JSONObject upUserImg(@RequestParam(value = "file") MultipartFile file) throws IOException {
        String name = file.getOriginalFilename();
        System.out.println(name);
        /*String path = "E:/IdeaProjects/ec_system/src/main/resources/static/img/header/banner/" + name;*/
        String path = fileaddress+"goods/" + name;
        file.transferTo(new File(path));
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("goodsImg", name);
        return jsonObject;
    }
    /*添加商品*/
    @RequestMapping("/addGoods")
    @ResponseBody
    public String addGoods(Goods goods){
        int rs = goodsService.addGoods(goods);
        if (rs>0){
            return "success";
        }else {
            return "fail";
        }
    }
    /*修改商品信息*/
    @RequestMapping("/updateGoods")
    @ResponseBody
    public String updateGoods(Goods goods){
        int rs = goodsService.updateGoods(goods);
        if (rs>0){
            return "success";
        }else {
           return "fail";
        }
    }
    /*通过店家获取商品*/
    @RequestMapping("/getAllGoodsByStore")
    @ResponseBody
    public List<Goods> getByStore(HttpSession httpSession){
        int userId = (int) httpSession.getAttribute("userId");
        Store store = storeService.selectByUserId(userId);
        List<Goods> goodsList = goodsService.getGoodsByStoreId(store.getStoreId());
        return goodsList;
    }
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序猿毕业分享网

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值