赞
踩
基于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等等
private OrderService orderService; @Autowired private CustomerAddressService customerAddressService; @Autowired private OrderShopDao orderShopDao; @Autowired private RoyaltyService royaltyService; @Autowired @Qualifier("alipayService") private AlipayService alipayService; @Autowired public Jedis jedis; /** * 评价界面 * * @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());
response.addCookie(cookie); return "redirect:/login.html"; } /** * 登录 * @param loginName * @param password * @return * @throws Exception */ @PostMapping("loginData.html") @ResponseBody @ImLog(type = "登录",mark = "用户 {loginName} 登录") public Result loginData(String loginName, String password, HttpServletResponse response)throws Exception{ EntityWrapper entityWrapper = new EntityWrapper(); entityWrapper.eq(UserTable.LOGIN_NAME,loginName); UserEntity userEntity = userService.selectOne(entityWrapper); if(userEntity==null){ return Result.error("用户名或密码错误"); } if(!password.equals(userEntity.getPassword())){ return Result.error("用户名或密码错误"); } RoleEntity roleEntity = roleService.selectById(userEntity.getRoleId()); if(roleEntity==null || roleEntity.getStatus()==false ){ return Result.error("用户无角色可用"); } Cookie cookie = new Cookie("login_key_auth",userEntity.getId()); cookie.setPath("/"); cookie.setMaxAge(3600000); response.addCookie(cookie); return Result.success("登录成功"); } }
response.addCookie(cookie); return Result.success(customerEntity.getId(),"登陆成功"); } } /** * 文章 */ @Controller @RequestMapping("article") public class MobileArticleController { @Autowired private ArticleService articleService; @Autowired private CustomerService customerService;
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"; } /** * 登陆 * @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(),"登陆成功");
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("保存成功"); } }
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"; } /** * 退出登陆 * @return * @throws Exception */ @RequestMapping("logOut.do") @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("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() + "+"); orderShopEntity.setCover(shopEntity.getCover()); orderShopEntity.setShopId(shopEntity.getId()); orderShopEntity.setCustomerId(userEntity.getId());
// // 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 */ @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;
/** * 保存界面 * @param model * @param id * @return * @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
@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); } }
* 用户提取佣金 * @param money * @return * @throws Exception */ @RequestMapping("tiqu.do") @ResponseBody public Result tiqu(String money)throws Exception{ 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("提取成功"); } } @Controller
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(); 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("成功"); } }
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"; } } @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 */
@Controller @RequestMapping("user") public class UserController { @Autowired private UserDao userDao; @Autowired private RoleService roleService; @Autowired private UserService userService; /** * 用户界面 * @param model * @return * @throws Exception */ @RequestMapping("list.htm") public String list(Model model)throws Exception{ List<UserEntity> list = userDao.list(); model.addAttribute("list",list); return "user/list"; } /** * 保存界面 * @param model * @param id * @return * @throws Exception */ @RequestMapping("save.htm") public String save(Model model,String id)throws Exception{ EntityWrapper entityWrapper = new EntityWrapper(); entityWrapper.eq(RoleTable.STATUS,true); List<RoleEntity> entities = roleService.selectList(entityWrapper); model.addAttribute("roles",entities); UserEntity userEntity = new UserEntity(); userEntity.setSex(true); userEntity.setStatus(true);
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"; } /** * 保存 * @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("用户保存成功"); }
/** * 保存 * @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 */ @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); } if(type==1){ //添加库存 entity.setStock(entity.getStock()+stock); }else{ //减少库存 if(entity.getStock()-stock<0){ return Result.error("库存不够"); }
public String save(Model model,String id)throws Exception{ EntityWrapper entityWrapper = new EntityWrapper(); entityWrapper.eq(RoleTable.STATUS,true); List<RoleEntity> entities = roleService.selectList(entityWrapper); model.addAttribute("roles",entities); 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("保存成功"); }
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("提取成功"); } } @Controller @RequestMapping("mobileShop") public class MobileShopController { @Autowired
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。