基于javaweb+mysql的springboot网上超市线上购物系统(java+springboot+mysql+thymeleaf+html)

基于javaweb+mysql的springboot网上超市线上购物系统(java+springboot+mysql+thymeleaf+html)

私信源码获取及调试交流

运行环境

Java≥8、MySQL≥5.7

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

基于javaweb+mysql的SpringBoot网上超市线上购物系统(java+springboot+mysql+thymeleaf+html)

管理员:

admin 123456

用户:

13511111111 123456

13511111112 123456

13511111113 123456

     * @return
     * @throws Exception
     */
    @RequestMapping("info.do")
    public String info(Model model)throws Exception{
        CustomerEntity customerEntity = Contants.getCustomer();
        model.addAttribute("customer",customerEntity);
        return "mobile/my";
    }

    /**
     * 我的界面 -- 修改
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("myUpdate.do")
    public String my_update(Model model)throws Exception{
        CustomerEntity customerEntity = Contants.getCustomer();
        model.addAttribute("entity",customerEntity);
        return "mobile/my_update";
    }

    /**
     * 我的界面 -- 修改
     * @return
     * @throws Exception
     */
    @RequestMapping("myUpdateData.do")
    @ResponseBody
    public Result myUpdateData( CustomerEntity customerEntity)throws Exception{
        customerEntity.setId(Contants.getCustomer().getId());
        customerService.updateById(customerEntity);
        return Result.success("成功");
    }

    /**
     * 登陆界面
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("login.html")
    public String login(Model model) throws Exception{
        return "mobile/login";
    }


/**
 * 登录拦截器
 */
@Component
public class LoginInterceptor implements HandlerInterceptor {

    @Autowired
    private UserService userService;

    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
        if(!httpServletRequest.getRequestURI().endsWith("htm")){
            return true;
        }
        Cookie[] cookies =  httpServletRequest.getCookies();
        if(cookies==null || cookies.length==0){
            throw new NeedLoginException("需要登录");
        }
        String uid = "";
        for (Cookie cookie : cookies) {
            if(cookie.getName().equals("login_key_auth")){
                uid = cookie.getValue();
            }
        }
        if(StringUtils.isEmpty(uid)){
            throw new NeedLoginException("需要登录");
        }
        UserEntity userEntity = userService.selectById(uid);
        if(userEntity==null || userEntity.getStatus()==false){
            throw new NeedLoginException("需要登录");
        }
        Contants.USER_ENTITY_THREAD_LOCAL.set(userEntity);
        Cookie cookie = new Cookie("login_key_auth",userEntity.getId());
        cookie.setPath("/");
        cookie.setMaxAge(3600000);
        httpServletResponse.addCookie(cookie);
        return true;
    }
     * @throws Exception
     */
    @RequestMapping("save.do")
    public String save(Model model,String id)throws Exception{
        CustomerAddressEntity entity = new CustomerAddressEntity();
        if(!StringUtils.isEmpty(id)){
            entity = service.selectById(id);
        }
        model.addAttribute("entity",entity);
        return "mobile/address_save";
    }

    /**
     * 保存
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("saveData.do")
    @ResponseBody
    public Result save(Model model, CustomerAddressEntity entity)throws Exception{
        CustomerEntity customerEntity = Contants.getCustomer();
        entity.setCustomerId(customerEntity.getId());
        if(StringUtils.isEmpty(entity.getId())){
            entity.setId(IdWorkerUtil.getId());
            service.insert(entity);
        }else{
            service.updateById(entity);
        }
        return Result.success("保存成功");
    }

    /**
     * 删除
     * @param id
     * @return
     * @throws Exception
     */
    @PostMapping("del.do")
    @ResponseBody
    public Result del(String id)throws Exception{
        service.deleteById(id);
        return Result.success("保存成功");
    }
}

    @ResponseBody
    public Result logOut( HttpServletResponse response)throws Exception{
        Cookie cookie = new Cookie("login_key_auth_customer","-1");
        cookie.setPath("/");
        cookie.setMaxAge(0);
        response.addCookie(cookie);
        return Result.success("退出成功");
    }

    /**
     * 登陆
     * @return
     * @throws Exception
     */
    @RequestMapping("loginData.html")
    @ResponseBody
    public Result loginData(String phone,String password, HttpServletResponse response)throws Exception{
        EntityWrapper entityWrapper = new EntityWrapper();
        entityWrapper.eq("phone",phone);
        CustomerEntity customerEntity = customerService.selectOne(entityWrapper);
        if(customerEntity==null){
            return Result.error("用户不存在");
        }
        if(!customerEntity.getPassword().equals(password)){
            return Result.error("密码错误");
        }
        Cookie cookie = new Cookie("login_key_auth_customer",customerEntity.getId());
        cookie.setPath("/");
        cookie.setMaxAge(3600000);
        response.addCookie(cookie);
        return Result.success(customerEntity.getId(),"登陆成功");
    }

    /**
     * 登陆界面
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("reg.html")
    public String reg(Model model) throws Exception{
        return "mobile/reg";
    }

    /**
     * 登陆
        if(userEntity==null || userEntity.getStatus()==false){
            throw new NeedLoginException("需要登录");
        }
        Contants.USER_ENTITY_THREAD_LOCAL.set(userEntity);
        Cookie cookie = new Cookie("login_key_auth",userEntity.getId());
        cookie.setPath("/");
        cookie.setMaxAge(3600000);
        httpServletResponse.addCookie(cookie);
        return true;
    }

    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {

    }
}

@Controller
@RequestMapping("royalty")
public class RoyaltyController {

    @Autowired
    private RoyaltyService royaltyService;

    /**
     * 列表界面
            for (OrderEntity order : orders) {
                wrapper = new EntityWrapper();
                wrapper.eq("order_id",order.getId());
                List<OrderShopEntity> orderShops = orderShopService.selectList(wrapper);
                order.setOrderShops(orderShops);
            }
        }
        model.addAttribute("orders",orders);
        return "mobile/orderList";
    }
    @Autowired
    private RoyaltyService royaltyService;

    /**
     *  订单结算
     * @param ids 购物车ids
     * @param nums 数量
     * @return
     * @throws Exception
     */
    @RequestMapping("jiesuan.do")
    @ResponseBody
    public Result jiesuan(String ids[], Integer nums[], String prices[], OrderEntity orderEntity,String addressId)throws Exception{
        CustomerEntity userEntity = Contants.getCustomer();

        orderEntity.setId(IdWorkerUtil.getId());
        orderEntity.setCustomerId(userEntity.getId());
        orderEntity.setStatus(1);
        orderEntity.setTime(new Date());

        CustomerAddressEntity customerAddressEntity = customerAddressService.selectById(addressId);
        if(customerAddressEntity==null){
            return  Result.error("请选择收货地址");
        }
        //验证库存是否足够
        for (int i = 0; i <ids.length ; i++) {
            ShoppingGatEntity shoppingGatEntity = shoppingGatService.selectById(ids[i]);
            ShopEntity shopEntity = shopService.selectById(shoppingGatEntity.getShopId());
            if(shopEntity.getStock()==null || shopEntity.getStock()<shoppingGatEntity.getNum()){
                return Result.error(shopEntity.getName()+"库存不足");
            }
        }

        orderEntity.setAddress(customerAddressEntity.getAddress());
        orderEntity.setName(customerAddressEntity.getName());
        orderEntity.setPhone(customerAddressEntity.getPhone());
        orderService.insert(orderEntity);
        for (int i = 0; i <ids.length ; i++) {
            ShoppingGatEntity shoppingGatEntity = shoppingGatService.selectById(ids[i]);
            ShopEntity shopEntity = shopService.selectById(shoppingGatEntity.getShopId());
            OrderShopEntity orderShopEntity = new OrderShopEntity();
            orderShopEntity.setId(IdWorkerUtil.getId());
            orderShopEntity.setPrice(new BigDecimal(prices[i]));
        Page<ChildTypeEntity> paged = new Page();
        paged.setSize(limit);
        paged.setCurrent(page);
        Page<ChildTypeEntity> userTablePage = childTypeService.selectPage(paged, entityWrapper);

        PageVo<ChildTypeEntity> pageVo = new PageVo<>();
        pageVo.setCode(0);
        pageVo.setCount(paged.getTotal());
        pageVo.setData(userTablePage.getRecords());
        pageVo.setPageNum(limit);
        pageVo.setPageSize(page);
        return pageVo;

    }

    /**
     * 保存界面
     * @param model
     * @return
     */
    @GetMapping("savePage.htm")
    public String savePage(Model model){
        return  "childType/save";
    }

    /**
     * 保存
     * @param model
     * @return
     */
    @PostMapping("save.htm")
    @ResponseBody
    public Result savePage(Model model , ChildTypeEntity entity){
        if(entity.getId()==null || entity.getId().equals("")){
            entity.setId(IdWorker.get32UUID());
            childTypeService.insert(entity);
        }
        return Result.success("用户保存成功");
    }

}

    public String list(Model model) throws Exception{
        CustomerEntity userEntity = Contants.getCustomer();
        EntityWrapper wrapper = new EntityWrapper();
        wrapper.eq(OrderTable.CUSTOMER_ID,userEntity.getId()).orderBy("time",false);
        List<OrderEntity> orders = orderService.selectList(wrapper);
        if(orders!=null){
            for (OrderEntity order : orders) {
                wrapper = new EntityWrapper();
                wrapper.eq("order_id",order.getId());
                List<OrderShopEntity> orderShops = orderShopService.selectList(wrapper);
                order.setOrderShops(orderShops);
            }
        }
        model.addAttribute("orders",orders);
        return "mobile/orderList";
    }
    @Autowired
    private RoyaltyService royaltyService;

    /**
     *  订单结算
     * @param ids 购物车ids
     * @param nums 数量
     * @return
     * @throws Exception
     */
    @RequestMapping("jiesuan.do")
    @ResponseBody
    public Result jiesuan(String ids[], Integer nums[], String prices[], OrderEntity orderEntity,String addressId)throws Exception{
        CustomerEntity userEntity = Contants.getCustomer();

        orderEntity.setId(IdWorkerUtil.getId());
        orderEntity.setCustomerId(userEntity.getId());
        orderEntity.setStatus(1);
        orderEntity.setTime(new Date());

        CustomerAddressEntity customerAddressEntity = customerAddressService.selectById(addressId);
        if(customerAddressEntity==null){
            return  Result.error("请选择收货地址");
        }
        //验证库存是否足够
        for (int i = 0; i <ids.length ; i++) {
            ShoppingGatEntity shoppingGatEntity = shoppingGatService.selectById(ids[i]);
            ShopEntity shopEntity = shopService.selectById(shoppingGatEntity.getShopId());
            if(shopEntity.getStock()==null || shopEntity.getStock()<shoppingGatEntity.getNum()){
                return Result.error(shopEntity.getName()+"库存不足");
            }
        }

@RestController
@RequestMapping("chatRoom")
public class ChatRoomController {

    @Autowired
    private ChatRoomDao chatRoomDao;

    @Autowired
    private ChatRoomService chatRoomService;

    @PostMapping("listkk.html")
    public Result listkk()throws Exception{
        List<Map<String,Object>> l =  chatRoomDao.list();
        return Result.success(l);
    }

    /**
     * 阅读
     * @return
     * @throws Exception
     */
    @PostMapping("read.html")
    public Result read(String userId)throws Exception{
        chatRoomDao.read(userId);
        return Result.success("已阅读");
    }

    /**
     * 消息列表
     * @return
     */
    @RequestMapping("list.html")
    public Result listx(String userId){
        //首先查询帮助信息
        EntityWrapper entityWrapper = new EntityWrapper();
        //消息列表
        entityWrapper
     
        PageVo<ArticleEntity> pageVo = new PageVo<>();
        pageVo.setCode(0);
        pageVo.setCount(paged.getTotal());
     
        pageVo.setPageNum(limit);
        pageVo.setPageSize(page);
        return pageVo;

    }

    /**
     * 界面
     * @return
     * @throws Exception
     */
    @GetMapping("add.do")
    public String add(Model model)throws Exception{
        List<ShopEntity> shopEntities =  shopService.selectList(new EntityWrapper<>());
        model.addAttribute("shopEntities",shopEntities);
        return "mobile/article/add";
    }

    /**
     * 保存数据
     * @return
     * @throws Exception
     */
    @RequestMapping("addData.do")
    @ResponseBody
    public Result addDatax(ArticleEntity articleEntity, HttpSession session)throws Exception{
        articleEntity.setId(IdWorkerUtil.getId());
        articleEntity.setTime(new Date());
        articleEntity.setStatus(0);
        articleEntity.setCustomerId(Contants.getCustomer().getId());
        articleEntity.setTop(false);
        return Result.success("保存成功");
    }

    /**
     * 界面
     * @return
     * @throws Exception
     */
    @GetMapping("edit.do")
    public String edit(String id, Model model )throws Exception{
        List<ShopEntity> shopEntities =  shopService.selectList(new EntityWrapper<>());
        model.addAttribute("shopEntities",shopEntities);
            //一个一个字节的读取并写入
            while((temp=is.read())!=(-1))
            {
                os.write(temp);
            }
            os.flush();
            os.close();
            is.close();
            InputStream inputStream = new FileInputStream(file1.getPath());
            byte[] b = new byte[inputStream.available()];
            inputStream.read(b);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return Result.error("上传文件失败");
        }
        return Result.success("/file/pic?pictureName="+fileName,"文件上传成功");
    }

    /**
     * 获取本地图片
     * @param pictureName //文件名
     * @return
     */
    @RequestMapping("/pic")
    public void ShowImg(String pictureName, HttpServletRequest request, HttpServletResponse response) throws IOException {
        //这里是存放图片的文件夹地址
        FileInputStream fileIs=null;
        OutputStream outStream = null;
        try {
            fileIs = new FileInputStream(FILE_PATH+"/"+pictureName);
            //得到文件大小
            int i=fileIs.available();
            //准备一个字节数组存放二进制图片
            byte data[]=new byte[i];
            //读字节数组的数据
            fileIs.read(data);
            //设置返回的文件类型
            response.setContentType("application/octet-stream;charset=UTF-8");
            //得到向客户端输出二进制数据的对象
            outStream=response.getOutputStream();
            //输出数据
            for (ShoppingGatEntity gat : gats) {
                ShopEntity shopEntity = shopService.selectById(gat.getShopId());
                gat.setShopEntity(shopEntity);
            }
        }
        model.addAttribute("gats",gats);
       List<CustomerAddressEntity> customerAddressEntities =   customerAddressService.selectList(entityWrapper);
        model.addAttribute("customerAddressEntities",customerAddressEntities);
        return "mobile/gat";
    }

    /**
     * 删除
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping("delete.do")
    @ResponseBody
    public Result delete(String id)throws Exception{
        CustomerEntity userEntity = Contants.getCustomer();
        if(StringUtils.isEmpty(id)){
            EntityWrapper entityWrapper = new EntityWrapper();
            entityWrapper.eq(ShoppingGatTable.CUSTOMER_ID,userEntity.getId());
            shoppingGatService.delete(entityWrapper);
        }else{
            shoppingGatService.deleteById(id);
        }
        return Result.success("成功");
    }

    /**
     * 添加到购物车
     * @param shopId
     * @return
     * @throws Exception
     */
    @RequestMapping("add.do")
    @ResponseBody
    public Result add(String shopId,Integer num,String customerId)throws Exception{
        CustomerEntity userEntity = Contants.getCustomer();
        userService.deleteById(id);
        return Result.success("保存成功");
    }

}

@Controller
@RequestMapping("customerAddress")
public class CustomerAddressController {

    @Autowired
    private CustomerAddressService service;

    /**
     * 列表界面
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("list.do")
    public String list(Model model)throws Exception{
        CustomerEntity customerEntity = Contants.getCustomer();
        EntityWrapper wrapper = new EntityWrapper();
    @RequestMapping("add.do")
    @ResponseBody
    public Result add(String shopId,Integer num,String customerId)throws Exception{
        CustomerEntity userEntity = Contants.getCustomer();
        EntityWrapper entityWrapper = new EntityWrapper();
        entityWrapper.eq(ShoppingGatTable.CUSTOMER_ID,userEntity.getId())
                .eq(ShoppingGatTable.SHOP_ID,shopId);
        ShoppingGatEntity gatEntity = shoppingGatService.selectOne(entityWrapper);
        if(gatEntity!=null){
            gatEntity.setNum(gatEntity.getNum()+num);
            shoppingGatService.updateById(gatEntity);
        }else{
            gatEntity = new ShoppingGatEntity();
            gatEntity.setId(IdWorker.get32UUID());
            gatEntity.setNum(num);
            gatEntity.setShopId(shopId);
            gatEntity.setCustomerId(userEntity.getId());
            gatEntity.setCid(customerId);
            shoppingGatService.insert(gatEntity);
        }
        return Result.success("成功");
    }

}

        Cookie cookie = new Cookie("login_key_auth_customer",customerEntity.getId());
        cookie.setPath("/");
        cookie.setMaxAge(3600000);
        response.addCookie(cookie);
        return Result.success(customerEntity.getId(),"登陆成功");
    }

    /**
     * 登陆界面
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("reg.html")
    public String reg(Model model) throws Exception{
        return "mobile/reg";
    }

    /**
     * 登陆
     * @return
     * @throws Exception
     */
    @RequestMapping("regData.html")
    @ResponseBody
    public Result regData( CustomerEntity customerEntity, HttpServletResponse response)throws Exception{
        customerEntity.setId(IdWorkerUtil.getId());
        customerEntity.setHeader("/img/a5.jpg");
        customerService.insert(customerEntity);
        Cookie cookie = new Cookie("login_key_auth_customer",customerEntity.getId());
        cookie.setPath("/");
        cookie.setMaxAge(3600000);
        response.addCookie(cookie);
        return Result.success(customerEntity.getId(),"登陆成功");
    }

}

            //得到向客户端输出二进制数据的对象
            outStream=response.getOutputStream();
            //输出数据
            outStream.write(data);
            outStream.flush();
        } catch (Exception e) {
            return;
        }finally {
            if(outStream!=null){
                //关闭输出流
                outStream.close();
                //关闭输入流
                fileIs.close();
            }
        }
    }
}

/**
 * 商品管理
 */
@Controller
@RequestMapping("shop")
public class ShopController {

    @Autowired
    private ShopService service;

    @Autowired
    private ShopTypeService shopTypeService;

    /**
        model.addAttribute("entity",entity);
        return "shoptype/save";
    }

    /**
     * 保存
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("saveData.htm")
    @ResponseBody
    public Result save(Model model, ShopTypeEntity entity)throws Exception{
        if(StringUtils.isEmpty(entity.getId())){
            entity.setId(IdWorkerUtil.getId());
            service.insert(entity);
        }else{
            service.updateById(entity);
        }
        return Result.success("保存成功");
    }

    /**
     * 删除
     * @param id
     * @return
     * @throws Exception
     */
    @PostMapping("del.htm")
    @ResponseBody
    public Result del(String id)throws Exception{
        service.deleteById(id);
        return Result.success("保存成功");
    }

}

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值