基于javaweb+mysql的springboot在线蛋糕销售商城(java+springboot+maven+mysql+thymeleaf+html+redis)

基于javaweb+mysql的springboot在线蛋糕销售商城(java+springboot+maven+mysql+thymeleaf+html+redis)

运行环境

Java≥8、MySQL≥5.7

开发工具

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

适用

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

功能说明

基于javaweb+mysql的SpringBoot在线蛋糕销售商城(java+springboot+maven+mysql+thymeleaf+html+redis)

一、项目简述

功能: 主页显示商品; 所有蛋糕商品展示,可进行商品搜索; 点击商品进入商品详情页,具有立即购买功能,可增减购买商品数量亦可手动输入,热销商品展示。 立即购买进入确认订单页面,可选择已经添加的地址,亦可新增地址。 可选择购买哪些商品,可删除不需要的商品。 点击结算进入确认订单页面,确认后提交订单。后台管理:(修改密码等),商品管理(商品批量添加、上下架等),订单管理。

二、项目运行

环境配置:

Jdk1.8 + Tomcat8.5 + mysql + Eclispe(IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持)

项目技术:

JSP +Springboot+ SpringMVC + MyBatis + ThymeLeaf + FTP+ JavaScript + JQuery + Ajax + maven等等

    @Autowired
    private ShopTypeService shopTypeService;

    @Autowired
    private ShopService shopService;

    @Autowired
    private ArticleService articleService;
    @Autowired
    private CustomerService customerService;

    @Autowired
    private ChildTypeService childTypeService;

    /**
     * 首页
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("/")
    public String home(Model model)throws Exception{
        CustomerEntity customerEntity = Contants.getCustomer();
        if(customerEntity!=null){
            model.addAttribute("customer",customerEntity);
        }

        return "shoping/index";
    }

    @RequestMapping("articleHome.html")
    public String articleHome(Model model)throws Exception{
        //查询置顶
        EntityWrapper wrapper = new EntityWrapper();
        wrapper.eq(ArticleTable.STATUS,1).eq("top",1).orderBy("time",false);
        List<ArticleEntity> topArticle =  articleService.selectList(wrapper);
        if(topArticle!=null && !topArticle.isEmpty()){
            for (ArticleEntity articleEntity : topArticle) {
                articleEntity.setCustomerName("系统发布");
                CustomerEntity userEntity = customerService.selectById(articleEntity.getCustomerId());
                articleEntity.setCustomerEntity(userEntity);
            }
        }
        model.addAttribute("topArticle",topArticle);

        //查询分类
        List<ChildTypeEntity> list =   childTypeService.selectList(new EntityWrapper<>());
        model.addAttribute("childTypes",list);
    private OrderShopDao orderShopDao;

    @Autowired
    private ArticleService articleService;

    @RequestMapping("info.html")
    public String info(String id,String customerId, Model model)throws Exception{
        ShopEntity shopEntity =  shopService.selectById(id);
        model.addAttribute("shop",shopEntity);
        model.addAttribute("id",id);
        List<OrderShopEntity> list = orderShopDao.list(id);
        model.addAttribute("list",list);
        model.addAttribute("customerId",customerId);
        return "mobile/shop_info";
    }

    /**
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping("aList.html")
    @ResponseBody
    public Result shopList(String id)throws Exception{
        ShopEntity shopEntity =  shopService.selectById(id);
        if(StringUtils.isEmpty(shopEntity.getLabel())){
            return Result.success("无");
        }
        String[] lebel = shopEntity.getLabel().split(",");
        //查询
        List<String> ids = new ArrayList<>();
        for (String s : lebel) {
            EntityWrapper wrapper = new EntityWrapper();
            wrapper.like("label",s);
            List<ArticleEntity> shops = articleService.selectList(wrapper);
            if(shops!=null){
                for (ArticleEntity shop : shops) {
                    ids.add(shop.getId());
                }
            }
        }
        EntityWrapper wrapper = new EntityWrapper();
        wrapper.in("id",ids).orderBy("rand()");
        List<ArticleEntity> shops = articleService.selectList(wrapper);
        if(shops!=null){
            if(shops.size()>3){
                shops = shops.subList(0,3);
            }
        }

        return Result.success(shops);
    }
    }
}

@Controller
@RequestMapping("file")
public class ImgControllerNoCos {
    public static final String FILE_PATH = System.getProperty("user.dir") + "\\src\\main\\resources\\static\\images\\";
    static {
        File file = new File(FILE_PATH);
        file.mkdirs();
    }

    /**
     * 文件上传返回code为200
     * @param file
     * @return
     * @throws Exception
     */
    @PostMapping("/upload")
    @ResponseBody
    public Result uplaod(@RequestParam("file") MultipartFile file)throws Exception {
        //用来检测程序运行时间
        String fileName =  IdWorker.get32UUID() +file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
        try {
            File file1 = new File(FILE_PATH+"\\"+fileName);
            file1.createNewFile();
            //获取输出流
            OutputStream os=new FileOutputStream(file1.getPath());
    }

    /**
     * 分页
     * @param model
     * @return
     * @throws Exception
     */
    @GetMapping("page.htm")
    @ResponseBody
    public PageVo indexPage(Model model, String name, int page , int limit)throws Exception{

        EntityWrapper entityWrapper = new EntityWrapper();
        entityWrapper.like(ChildTypeTable.NAME,name);

        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";
    }

    /**
     * 保存

@Controller
@RequestMapping("file")
public class ImgControllerNoCos {
    public static final String FILE_PATH = System.getProperty("user.dir") + "\\src\\main\\resources\\static\\images\\";
    static {
        File file = new File(FILE_PATH);
        file.mkdirs();
    }

    /**
     * 文件上传返回code为200
     * @param file
     * @return
     * @throws Exception
     */
    @PostMapping("/upload")
    @ResponseBody
    public Result uplaod(@RequestParam("file") MultipartFile file)throws Exception {
        //用来检测程序运行时间
        String fileName =  IdWorker.get32UUID() +file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
        try {
            File file1 = new File(FILE_PATH+"\\"+fileName);
            file1.createNewFile();
            //获取输出流
            OutputStream os=new FileOutputStream(file1.getPath());
            //获取输入流 CommonsMultipartFile 中可以直接得到文件的流
            InputStream is=file.getInputStream();
            int temp;
            //一个一个字节的读取并写入
            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,"文件上传成功");
        userEntity.setSex(true);
        userEntity.setStatus(true);
        if(!StringUtils.isEmpty(id)){
            userEntity = userService.selectById(id);
        }
        model.addAttribute("userEntity",userEntity);
        return "user/save";
    }

    /**
     * 保存
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("saveData.htm")
    @ResponseBody
    @ImLog(type = "用户",mark = "保存用户 {name}")
    public Result save(Model model, UserEntity userEntity)throws Exception{
        if(StringUtils.isEmpty(userEntity.getId())){
            userEntity.setId(IdWorker.get32UUID());
            userEntity.setTime(new Date());
            userService.insert(userEntity);
        }else{
            userService.updateById(userEntity);
        }
        return Result.success("保存成功");
    }

    /**
     * 保存
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("del.htm")
    @ResponseBody
    @ImLog(type = "用户",mark = "删除用户 {id}")
    public Result del(Model model, String id )throws Exception{
        userService.deleteById(id);
        return Result.success("保存成功");
    }
    }

    /**
     * 根据文章ID推荐商品
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping("shopList.html")
    @ResponseBody
    public Result shopList(String id)throws Exception{
        ArticleEntity articleEntity = articleService.selectById(id);
        if(StringUtils.isEmpty(articleEntity.getLabel())){
            return Result.success("无");
        }
        String[] lebel = articleEntity.getLabel().split(",");
        //查询
        List<String> ids = new ArrayList<>();
        for (String s : lebel) {
            EntityWrapper wrapper = new EntityWrapper();
            wrapper.like("label",s);
            List<ShopEntity> shops = shopService.selectList(wrapper);
            if(shops!=null){
                for (ShopEntity shop : shops) {
                    ids.add(shop.getId());
                }
            }
        }
        EntityWrapper wrapper = new EntityWrapper();
        wrapper.in("id",ids).orderBy("rand()");
        List<ShopEntity> shops = shopService.selectList(wrapper);
        if(shops!=null){
            if(shops.size()>3){
                shops = shops.subList(0,3);
            }
        }
        return Result.success(shops);
    }

    /**
     * 界面
     * @return
     * @throws Exception
     */
    @RequestMapping("save.htm")
    public String save(Model model,String id)throws Exception{
        ShopEntity entity = new ShopEntity();
        entity.setStatus(true);
        entity.setHot(false);
        if(!StringUtils.isEmpty(id)){
            entity = service.selectById(id);
        }
        model.addAttribute("entity",entity);

        List<ShopTypeEntity> types =  shopTypeService.selectList(new EntityWrapper<>());
        model.addAttribute("types",types);
        return "shop/save";
    }

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

    /**
     * 删除
     * @param id
     * @return
     * @throws Exception
                integral = 0;
            }
            jedis.set("WSY-FLAG", "true");
            jedis.set("WSY-INTEGRAL", String.valueOf(integral));
            jedis.set("WSY-USERID", customerEntity.getId());
        } else {
            jedis.set("WSY-FLAG", "false");
        }
        name = name.substring(0, name.length() - 1);
        String id = IdUtil.simpleUUID();
//        String pays = alipayService.webPagePay(id, pay, name);
        return "下单成功";
    }

    @RequestMapping("/payresult")
    private String payResult() {
        List<String> ids = jedis.lrange("WSY-IDS", 0, -1);
        jedis.del("WSY-IDS");
        for (String id : ids) {
            shoppingGatService.deleteById(id);
        }
        String flag = jedis.get("WSY-FLAG");
        if ("true".equals(flag)) {
            String integralStr = jedis.get("WSY-INTEGRAL");
            Integer integralInt = Integer.valueOf(integralStr);
            String userId = jedis.get("WSY-USERID");
            CustomerEntity customerEntity = customerService.selectById(userId);
            customerEntity.setIntegral(integralInt);
            customerService.updateById(customerEntity);
        }
        String orderId = jedis.get("WSY-ORDERID");
        OrderEntity orderEntity = new OrderEntity();
        orderEntity.setId(orderId);
        orderEntity.setStatus(1);
        orderService.updateById(orderEntity);
        return "shoping/index";
    }
}

    @ResponseBody
    public Result stock(Model model, Integer stock,String id ,Integer type)throws Exception{
        ShopEntity entity = service.selectById(id);
        if(entity.getStock()==null){
            entity.setStock(0);
        }
        if(type==1){ //添加库存
            entity.setStock(entity.getStock()+stock);
        }else{ //减少库存
            if(entity.getStock()-stock<0){
                return Result.error("库存不够");
            }
            entity.setStock(entity.getStock()-stock);
        }
        service.updateById(entity);
        return Result.success("保存成功");
    }

}

        return "mobile/article/edit";
    }

    /**
     * 保存数据
     * @return
     * @throws Exception
     */
    @RequestMapping("editData.do")
    @ResponseBody
    public Result editData(ArticleEntity articleEntity)throws Exception{
        articleService.updateById(articleEntity);
        return Result.success("保存成功");
    }

}

@Controller
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("list.do")
    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";
    }

    /**
     * 订单结算
     *
     * @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();
        String orderId = IdWorkerUtil.getId();
        jedis.set("WSY-ORDERID", orderId);
        orderEntity.setId(orderId);
        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]);
     * 保存数据
     * @return
     * @throws Exception
     */
    @RequestMapping("editData.do")
    @ResponseBody
    public Result editData(ArticleEntity articleEntity)throws Exception{
        articleService.updateById(articleEntity);
        return Result.success("保存成功");
    }

}

@Controller
@RequestMapping("shoppingGat")
public class ShoppingGatController {

    @Autowired
    private ShoppingGatService shoppingGatService;

    @Autowired
    private ShopService shopService;

    @Autowired
    private CustomerAddressService customerAddressService;
    @Autowired
    private CustomerService customerService;
    @Autowired
    private RoyaltyService royaltyService;

    /**
    }

    /**
     * 分页
     * @param model
     * @return
     * @throws Exception
     */
    @GetMapping("page.htm")
    @ResponseBody
    public PageVo indexPage(Model model, String name, int page , int limit)throws Exception{

        EntityWrapper entityWrapper = new EntityWrapper();
        entityWrapper.like(ChildTypeTable.NAME,name);

        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";
    }

    /**

/**
 * 首页
 */
@Controller
public class HomeController {

    @Autowired
    private ShopTypeService shopTypeService;

    @Autowired
    private ShopService shopService;

    @Autowired
    private ArticleService articleService;
    @Autowired
    private CustomerService customerService;

    @Autowired
    private ChildTypeService childTypeService;

    /**
     * 首页
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("/")
    public String home(Model model)throws Exception{
        CustomerEntity customerEntity = Contants.getCustomer();
        if(customerEntity!=null){
            model.addAttribute("customer",customerEntity);
        }

        return "shoping/index";
    }

    @RequestMapping("articleHome.html")
    public String articleHome(Model model)throws Exception{
        //查询置顶
        EntityWrapper wrapper = new EntityWrapper();
        wrapper.eq(ArticleTable.STATUS,1).eq("top",1).orderBy("time",false);
        List<ArticleEntity> topArticle =  articleService.selectList(wrapper);
        if(topArticle!=null && !topArticle.isEmpty()){
            for (ArticleEntity articleEntity : topArticle) {
                articleEntity.setCustomerName("系统发布");

/**
 * Created by Wsy
 */
@Controller
@RequestMapping("fileNoCos")
public class ImgController {
//    //secretId
//    public static final String secretId = "";
//    //secretKey
//    public static final String secretKey = "";
//    //COS桶的根路径
//    public static final String BASEURL = "";
//    //桶的名称
//    public static final String BUCKETNAME = "";
//    //桶的key(文件夹名称)
//    public static final String KEY = "";
//    //你的REGION
//    public static final String REGION = "";
//    /**
//     * MultipartFile-->File
//     * @param multipartFile
//     * @return
//     */
//    private static File transferToFile(MultipartFile multipartFile) {
//        File file = null;
//        try {
//            String originalFilename = multipartFile.getOriginalFilename();
//            System.out.println(originalFilename);
//            String[] filename = originalFilename.split("\\.");
//            file = File.createTempFile(filename[0], filename[1]);
//            multipartFile.transferTo(file);
//            file.deleteOnExit();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//        return file;
//    }
//
//    /**
//     * 文件上传返回code为200
//     *
//     * @param file
//     * @return
//     * @throws Exception
//     */
//    @PostMapping("/upload")
//    @ResponseBody
//    public Result uplaod(@RequestParam("file") MultipartFile file) throws Exception {
//        //用来检测程序运行时间
	            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();
	            //输出数据
	            outStream.write(data);
	            outStream.flush();
	        } catch (Exception e) {
	            return;
	        }finally {
	            if(outStream!=null){
	                //关闭输出流
	                outStream.close();
	                //关闭输入流
	                fileIs.close();
	            }
	        }
                if(menuids.contains(menuEntity.getId())){
                    menuEntity.setAuth(true);
                }
            }
        }
        model.addAttribute("menuEntities",menuEntities);
        model.addAttribute("roleId",id);
        return "role/auth";
    }

    /**
     * 权限分配
     * @param ids
     * @param model
     * @return
     * @throws Exception
     */
    @RequestMapping("authData.htm")
    @ResponseBody
    @ImLog(type = "角色",mark = "角色分配权限 {id} {ids}")
    public Result data(String[] ids,String roleId,Model model)throws Exception{
        List<String> list = new ArrayList<>();
        for (String id : ids) {
            list.add(id);
        }
        List<MenuEntity> menuEntities = menuService.selectBatchIds(list);
        //删除原有权限
        EntityWrapper entityWrapper = new EntityWrapper();
        entityWrapper.eq(RoleMenuTable.ROLE_ID,roleId);
        roleMenuService.delete(entityWrapper);
        Set<String> set = new HashSet<>();
        //循环添加新的权限
        for (MenuEntity menuEntity : menuEntities) {
            set.add(menuEntity.getPId());
        }
        for (String s : set) {
            RoleMenuEntity roleMenuEntity = new RoleMenuEntity();
            roleMenuEntity.setId(IdWorkerUtil.getId());
            roleMenuEntity.setMenuId(s);
            roleMenuEntity.setRoleId(roleId);
            roleMenuService.insert(roleMenuEntity);
        }
        for (String s : list) {
            RoleMenuEntity roleMenuEntity = new RoleMenuEntity();
            roleMenuEntity.setId(IdWorkerUtil.getId());

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值