赞
踩
基于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等等
@Controller @RequestMapping("shop") public class ShopController { @Autowired private ShopService service; @Autowired private ShopTypeService shopTypeService; /** * 界面 * @param model * @return */ @RequestMapping("list.htm") public String list(Model model){ List<ShopEntity> list = service.selectList(new EntityWrapper<>()); model.addAttribute("list",list); return "shop/list"; } /** * 保存界面 * @param model * @param id * @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
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); EntityWrapper entityWrapper = new EntityWrapper(); entityWrapper.eq(ArticleTable.STATUS,1); entityWrapper.orderBy("time",false); List<ArticleEntity> articleEntities = articleService.selectList(entityWrapper); if(articleEntities!=null && !articleEntities.isEmpty()){ for (ArticleEntity articleEntity : articleEntities) { articleEntity.setCustomerName("系统发布"); CustomerEntity userEntity = customerService.selectById(articleEntity.getCustomerId()); articleEntity.setCustomerEntity(userEntity); ChildTypeEntity childTypeEntity = childTypeService.selectById(articleEntity.getChildType()); if(childTypeEntity!=null){ articleEntity.setChildName(childTypeEntity.getName()); } } } model.addAttribute("articleEntities",articleEntities); return "mobile/articleHome"; } } package com.wsy.controller.admin;
// @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 = transferToFile(file); // // 1 初始化用户身份信息(secretId, secretKey)。 // COSCredentials cred = new BasicCOSCredentials(secretId, secretKey); // // 2 设置 bucket 的地域, COS 地域的简称请参照 https://cloud.tencent.com/document/product/436/6224 clientConfig 中包含了设置 region, https(默认 http), 超时, 代理等 set 方法, 使用可参见源码或者常见问题 Java SDK 部分。 // Region region = new Region(REGION); // ClientConfig clientConfig = new ClientConfig(region); 这里建议设置使用 https 协议 // clientConfig.setHttpProtocol(HttpProtocol.https); // // 3 生成 cos 客户端。 // COSClient cosClient = new COSClient(cred, clientConfig); // // 指定要上传的文件 // // 指定文件将要存放的存储桶 // String bucketName = BUCKETNAME; // // 指定文件上传到 COS 上的路径,即对象键。例如对象键为folder/picture.jpg,则表示将文件 picture.jpg 上传到 folder 路径下 // String key = KEY + fileName; // PutObjectRequest putObjectRequest = new PutObjectRequest(bucketName, key, file1); // PutObjectResult putObjectResult = cosClient.putObject(putObjectRequest); // } catch (Exception e) { // e.printStackTrace(); // return Result.error("上传文件失败"); // } // return Result.success(BASEURL + fileName, "文件上传成功"); // } 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
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); EntityWrapper entityWrapper = new EntityWrapper(); entityWrapper.eq(ArticleTable.STATUS,1); entityWrapper.orderBy("time",false); List<ArticleEntity> articleEntities = articleService.selectList(entityWrapper); if(articleEntities!=null && !articleEntities.isEmpty()){ for (ArticleEntity articleEntity : articleEntities) { articleEntity.setCustomerName("系统发布"); CustomerEntity userEntity = customerService.selectById(articleEntity.getCustomerId()); articleEntity.setCustomerEntity(userEntity); ChildTypeEntity childTypeEntity = childTypeService.selectById(articleEntity.getChildType()); if(childTypeEntity!=null){ articleEntity.setChildName(childTypeEntity.getName()); } } } model.addAttribute("articleEntities",articleEntities); return "mobile/articleHome"; } } package com.wsy.controller.admin;
* @param id * @return * @throws Exception */ @RequestMapping("comment.do") public String comment(String id, Model model) throws Exception { OrderShopEntity orderShopEntity = orderShopService.selectById(id); model.addAttribute("entity", orderShopEntity); return "mobile/comment"; } @RequestMapping("commentData.do") @ResponseBody public Result commentData(OrderShopEntity orderShopEntity) throws Exception { String content = orderShopEntity.getContent(); content = content.replace("操", "*"); content = content.replace("sb", "**"); content = content.replace("傻", "*"); orderShopEntity.setContent(content); orderShopService.updateById(orderShopEntity); orderShopEntity = orderShopService.selectById(orderShopEntity.getId()); Double num = orderShopDao.num(orderShopEntity.getShopId()); ShopEntity shopEntity = new ShopEntity(); shopEntity.setId(orderShopEntity.getShopId()); shopEntity.setScore(num); shopService.updateById(shopEntity); return Result.success(1); } /** * 收货 * * @param id * @return * @throws Exception */ @RequestMapping("shouhuo.do") @ResponseBody public Result shouhuo(String id) throws Exception { OrderEntity orderEntity = orderService.selectById(id); orderEntity.setStatus(3); orderService.updateById(orderEntity); return Result.success("欢迎下次光临"); } /** * 退货收货 * * @param id * @return
UserEntity userEntity = new UserEntity(); 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("保存成功"); }
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(); //输出数据 outStream.write(data); outStream.flush(); } catch (Exception e) { return; }finally { if(outStream!=null){ //关闭输出流 outStream.close(); //关闭输入流 fileIs.close(); }
RoyaltyEntity royaltyEntity = new RoyaltyEntity(); String id = Contants.getCustomer().getId(); BigDecimal bigDecimal = new BigDecimal(money); royaltyEntity.setId(IdWorkerUtil.getId()); royaltyEntity.setCustomer(id); royaltyEntity.setMark("用户提取佣金"); royaltyEntity.setTime(new Date()); royaltyEntity.setMoney(bigDecimal); royaltyService.insert(royaltyEntity); CustomerEntity customerEntity = customerService.selectById(id); money = money.replace("-",""); Integer integer = Integer.valueOf(money); customerEntity.setIntegral(customerEntity.getIntegral()+integer/10); customerService.updateById(customerEntity); return Result.success("提取成功"); } } package com.wsy.controller.mobile; @Controller @RequestMapping("mobileShop") public class MobileShopController { @Autowired private ShopService shopService; @Autowired
orderShopEntity.setCover(shopEntity.getCover()); orderShopEntity.setShopId(shopEntity.getId()); orderShopEntity.setCustomerId(userEntity.getId()); orderShopService.insert(orderShopEntity); shopEntity.setStock(shopEntity.getStock() - nums[i]); shopService.updateById(shopEntity); if (!StringUtils.isEmpty(shoppingGatEntity.getCid())) { RoyaltyEntity royaltyEntity = new RoyaltyEntity(); royaltyEntity.setId(IdWorkerUtil.getId()); royaltyEntity.setCustomer(shoppingGatEntity.getCid()); royaltyEntity.setMark("订单下单抽取提成"); royaltyEntity.setTime(new Date()); royaltyEntity.setMoney(shopEntity.getRoyalty().multiply(new BigDecimal(shoppingGatEntity.getNum()))); royaltyService.insert(royaltyEntity); } } jedis.set("WSY-SHOPID", name); return Result.success("订单结算成功"); } } package com.wsy.controller.common; /** * Created by Wsy */ @Controller @RequestMapping("fileNoCos") public class ImgController {
* @return * @throws Exception */ @RequestMapping("addData.htm") @ResponseBody public Result addDatax(ArticleEntity articleEntity, HttpSession session)throws Exception{ articleEntity.setId(IdWorkerUtil.getId()); articleEntity.setTime(new Date()); articleEntity.setStatus(1); articleEntity.setCustomerId("-1"); articleService.insert(articleEntity); 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);
RoleMenuEntity roleMenuEntity = new RoleMenuEntity(); roleMenuEntity.setId(IdWorkerUtil.getId()); roleMenuEntity.setMenuId(s); roleMenuEntity.setRoleId(roleId); roleMenuService.insert(roleMenuEntity); } return Result.success("权限保存成功"); } } package com.wsy.controller.mobile; @Controller @RequestMapping("mobileCustomer") public class MobileCustomerController { @Autowired private CustomerService customerService; /** * 我的界面 * @param model * @return * @throws Exception */ @RequestMapping("jump.html") public String my(Model model,String url)throws Exception{ model.addAttribute("url",url); return "mobile/jump"; } /** * 我的Data * @param model
* 订单结算 * * @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]); 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); String name = StrUtil.EMPTY; 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])); orderShopEntity.setNum(nums[i]); orderShopEntity.setOrderId(orderEntity.getId()); orderShopEntity.setName(shopEntity.getName()); name = name.concat(shopEntity.getName() + "+");
* @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 */ @GetMapping("info.html") public String info(String id, Model model)throws Exception{ ArticleEntity articleEntity = articleService.selectById(id); model.addAttribute("article",articleEntity); model.addAttribute("id",id); String[] lebel = articleEntity.getLabel().split(","); model.addAttribute("lebels",lebel); CustomerEntity customerEntity = customerService.selectById(articleEntity.getCustomerId()); model.addAttribute("customerEntity",customerEntity);
* @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 */ @PostMapping("del.htm") @ResponseBody public Result del(String id)throws Exception{ service.deleteById(id); return Result.success("保存成功"); } /** * 保存 * @param model * @return * @throws Exception */ @RequestMapping("stock.htm") @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);
* 角色界面 * @param model * @return * @throws Exception */ @GetMapping("list.htm") public String list(Model model)throws Exception{ List<RoleEntity> list = roleService.selectList(new EntityWrapper<>()); model.addAttribute("list",list); return "role/list"; } /** * 保存 * @param id * @param name * @return * @throws Exception */ @PostMapping("save.htm") @ResponseBody @ImLog(type = "角色",mark = "保存角色 {id} {name} {status}") public Result save(String id,String name,Boolean status)throws Exception{ RoleEntity roleEntity = new RoleEntity(); roleEntity.setName(name); roleEntity.setStatus(status); if(StringUtils.isEmpty(id)){ roleEntity.setId(IdWorker.get32UUID()); roleEntity.setTime(new Date()); roleService.insert(roleEntity); }else{ roleEntity.setId(id); roleService.updateById(roleEntity); } return Result.success("保存成功"); } /** * 删除 * @param id * @return * @throws Exception */ @PostMapping("del.htm") @ResponseBody @ImLog(type = "角色",mark = "删除角色 {id}") public Result del(String id)throws Exception{ roleService.deleteById(id); return Result.success("保存成功"); }
@Controller @RequestMapping("mobileShop") public class MobileShopController { @Autowired private ShopService shopService; @Autowired 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);
articleEntity.setChildName(childTypeEntity.getName()); } } } PageVo<ArticleEntity> pageVo = new PageVo<>(); pageVo.setCode(0); pageVo.setCount(paged.getTotal()); pageVo.setData(list); 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); articleService.insert(articleEntity); return Result.success("保存成功"); } /** * 界面 * @return
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。