Java女装商城系统的实现流程
一、项目简述功能
javaweb 网上商城系统,前台+后台管理,用户注册,登录,上哦展示,分组展示,搜索,收货地址管理,购物车管理,添加,购买,个人信息修改。订单查询等等,后台商品管理,分类管理,库存管理,订单管理,用户管理,信息修改等等.
二、项目运行
【Java女装商城系统的实现流程】环境配置: Jdk1.8 + Tomcats . 5 + mysql + Eclispe ( IntelliJ IDEA ,Eclispe , MyEclispe , sts 都支持)
项目技术: JSP + Spring + SpringMVC + MyBatis + html + cSS + Javascript + JQuery + Ajax + layui + maven 等等。
文章图片
文章图片
文章图片
文章图片
文章图片
后台管理平台登录代码:
/** * 后台管理-主页 */@Controllerpublic class AdminHomeController extends BaseController {@Resource(name = "adminService")private AdminService adminService; @Resource(name = "productOrderService")private ProductOrderService productOrderService; @Resource(name = "productService")private ProductService productService; @Resource(name = "userService")private UserService userService; /*** 转到后台管理-主页* @param session session对象* @param map 前台传入的Map* @return 响应数据* @throws ParseException 转换异常*/@RequestMapping(value = "https://www.it610.com/article/admin", method = RequestMethod.GET)public String goToPage(HttpSession session, Map map) throws ParseException {logger.info("获取管理员信息"); Object adminId = checkAdmin(session); if (adminId == null) {return "redirect:/admin/login"; }Admin admin = adminService.get(null, Integer.parseInt(adminId.toString())); map.put("admin", admin); logger.info("获取统计信息"); //产品总数Integer productTotal = productService.getTotal(null, new Byte[]{0, 2}); //用户总数Integer userTotal = userService.getTotal(null); //订单总数Integer orderTotal = productOrderService.getTotal(null, new Byte[]{3}); logger.info("获取图表信息"); map.put("jsonObject", getChartData(null,null,7)); map.put("productTotal", productTotal); map.put("userTotal", userTotal); map.put("orderTotal", orderTotal); logger.info("转到后台管理-主页"); return "admin/homePage"; } /*** 转到后台管理-主页(ajax方式)* @param session session对象* @param map 前台传入的Map* @return 响应数据* @throws ParseException 转换异常*/@RequestMapping(value = "https://www.it610.com/article/admin/home", method = RequestMethod.GET)public String goToPageByAjax(HttpSession session, Map map) throws ParseException {logger.info("获取管理员信息"); Object adminId = checkAdmin(session); if (adminId == null) {return "admin/include/loginMessage"; }Admin admin = adminService.get(null, Integer.parseInt(adminId.toString())); map.put("admin", admin); logger.info("获取统计信息"); Integer productTotal = productService.getTotal(null, new Byte[]{0, 2}); Integer userTotal = userService.getTotal(null); Integer orderTotal = productOrderService.getTotal(null, new Byte[]{3}); logger.info("获取图表信息"); map.put("jsonObject", getChartData(null, null,7)); logger.info("获取图表信息"); map.put("jsonObject", getChartData(null,null,7)); map.put("productTotal", productTotal); map.put("userTotal", userTotal); map.put("orderTotal", orderTotal); logger.info("转到后台管理-主页-ajax方式"); return "admin/homeManagePage"; } /*** 按日期查询图表数据(ajax方式)* @param beginDate 开始日期* @param endDate 结束日期* @return 响应数据* @throws ParseException 转换异常*/@ResponseBody@RequestMapping(value = "https://www.it610.com/article/admin/home/charts", method = RequestMethod.GET, produces = "application/json; charset=utf-8")public String getChartDataByDate(@RequestParam(required = false) String beginDate, @RequestParam(required = false) String endDate) throws ParseException {if (beginDate != null && endDate != null) {//转换日期格式SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd"); return getChartData(simpleDateFormat.parse(beginDate), simpleDateFormat.parse(endDate),7).toJSONString(); } else {return getChartData(null, null,7).toJSONString(); }} /*** 按日期获取图表数据* @param beginDate 开始日期* @param endDate 结束日期* @param days 天数* @return 图表数据的JSON对象* @throws ParseException 转换异常*/private JSONObject getChartData(Date beginDate,Date endDate,int days) throws ParseException {JSONObject jsonObject = new JSONObject(); SimpleDateFormat time = new SimpleDateFormat("yyyy-MM-dd", Locale.UK); SimpleDateFormat time2 = new SimpleDateFormat("MM/dd", Locale.UK); SimpleDateFormat timeSpecial = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.UK); //如果没有指定开始和结束日期if (beginDate == null || endDate == null) {//指定一周前的日期为开始日期Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, 1-days); beginDate = time.parse(time.format(cal.getTime())); //指定当前日期为结束日期cal = Calendar.getInstance(); endDate = cal.getTime(); } else {beginDate = time.parse(time.format(beginDate)); endDate = timeSpecial.parse(time.format(endDate) + " 23:59:59"); }logger.info("根据订单状态分类"); //未付款订单数统计数组int[] orderUnpaidArray = new int[7]; //未发货订单数统计叔祖int[] orderNotShippedArray = new int[7]; //未确认订单数统计数组int[] orderUnconfirmedArray = new int[7]; //交易成功订单数统计数组int[] orderSuccessArray = new int[7]; //总交易订单数统计数组int[] orderTotalArray = new int[7]; logger.info("从数据库中获取统计的订单集合数据"); ListorderGroupList = productOrderService.getTotalByDate(beginDate, endDate); //初始化日期数组JSONArray dateStr = new JSONArray(days); //按指定的天数进行循环for (int i = 0; i < days; i++) {//格式化日期串(MM/dd)并放入日期数组中Calendar cal = Calendar.getInstance(); cal.setTime(beginDate); cal.add(Calendar.DATE, i); String formatDate = time2.format(cal.getTime()); dateStr.add(formatDate); //该天的订单总数int orderCount = 0; //循环订单集合数据的结果集for(int j = 0; j < orderGroupList.size(); j++){OrderGroup orderGroup = orderGroupList.get(j); //如果该订单日期与当前日期一致if(orderGroup.getProductOrder_pay_date().equals(formatDate)){//从结果集中移除数据orderGroupList.remove(j); //根据订单状态将统计结果存入对应的订单状态数组中switch (orderGroup.getProductOrder_status()) {case 0://未付款订单orderUnpaidArray[i] = orderGroup.getProductOrder_count(); break; case 1://未发货订单orderNotShippedArray[i] = orderGroup.getProductOrder_count(); break; case 2://未确认订单orderUnconfirmedArray[i] = orderGroup.getProductOrder_count(); break; case 3://交易成功订单orderSuccessArray[i] = orderGroup.getProductOrder_count(); break; }//累加当前日期的订单总数orderCount += orderGroup.getProductOrder_count(); }}//将统计的订单总数存入总交易订单数统计数组orderTotalArray[i] = orderCount; }logger.info("返回结果集map"); jsonObject.put("orderTotalArray", orderTotalArray); jsonObject.put("orderUnpaidArray", orderUnpaidArray); jsonObject.put("orderNotShippedArray", orderNotShippedArray); jsonObject.put("orderUnconfirmedArray", orderUnconfirmedArray); jsonObject.put("orderSuccessArray", orderSuccessArray); jsonObject.put("dateStr",dateStr); return jsonObject; }}
商品信息控制层:
/** * @author yy */@Controller@RequestMapping("/admin")public class NewBeeMallGoodsController { @Resourceprivate NewBeeMallGoodsService newBeeMallGoodsService; @Resourceprivate NewBeeMallCategoryService newBeeMallCategoryService; @GetMapping("/goods")public String goodsPage(HttpServletRequest request) {request.setAttribute("path", "newbee_mall_goods"); return "admin/newbee_mall_goods"; } @GetMapping("/goods/edit")public String edit(HttpServletRequest request) {request.setAttribute("path", "edit"); //查询所有的一级分类ListfirstLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(0L), NewBeeMallCategoryLevelEnum.LEVEL_ONE.getLevel()); if (!CollectionUtils.isEmpty(firstLevelCategories)) {//查询一级分类列表中第一个实体的所有二级分类List secondLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(firstLevelCategories.get(0).getCategoryId()), NewBeeMallCategoryLevelEnum.LEVEL_TWO.getLevel()); if (!CollectionUtils.isEmpty(secondLevelCategories)) {//查询二级分类列表中第一个实体的所有三级分类List thirdLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(secondLevelCategories.get(0).getCategoryId()), NewBeeMallCategoryLevelEnum.LEVEL_THREE.getLevel()); request.setAttribute("firstLevelCategories", firstLevelCategories); request.setAttribute("secondLevelCategories", secondLevelCategories); request.setAttribute("thirdLevelCategories", thirdLevelCategories); request.setAttribute("path", "goods-edit"); return "admin/newbee_mall_goods_edit"; }}return "error/error_5xx"; } @GetMapping("/goods/edit/{goodsId}")public String edit(HttpServletRequest request, @PathVariable("goodsId") Long goodsId) {request.setAttribute("path", "edit"); NewBeeMallGoods newBeeMallGoods = newBeeMallGoodsService.getNewBeeMallGoodsById(goodsId); if (newBeeMallGoods == null) {return "error/error_400"; }if (newBeeMallGoods.getGoodsCategoryId() > 0) {if (newBeeMallGoods.getGoodsCategoryId() != null || newBeeMallGoods.getGoodsCategoryId() > 0) {//有分类字段则查询相关分类数据返回给前端以供分类的三级联动显示GoodsCategory currentGoodsCategory = newBeeMallCategoryService.getGoodsCategoryById(newBeeMallGoods.getGoodsCategoryId()); //商品表中存储的分类id字段为三级分类的id,不为三级分类则是错误数据if (currentGoodsCategory != null && currentGoodsCategory.getCategoryLevel() == NewBeeMallCategoryLevelEnum.LEVEL_THREE.getLevel()) {//查询所有的一级分类List firstLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(0L), NewBeeMallCategoryLevelEnum.LEVEL_ONE.getLevel()); //根据parentId查询当前parentId下所有的三级分类List thirdLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(currentGoodsCategory.getParentId()), NewBeeMallCategoryLevelEnum.LEVEL_THREE.getLevel()); //查询当前三级分类的父级二级分类GoodsCategory secondCategory = newBeeMallCategoryService.getGoodsCategoryById(currentGoodsCategory.getParentId()); if (secondCategory != null) {//根据parentId查询当前parentId下所有的二级分类List secondLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(secondCategory.getParentId()), NewBeeMallCategoryLevelEnum.LEVEL_TWO.getLevel()); //查询当前二级分类的父级一级分类GoodsCategory firestCategory = newBeeMallCategoryService.getGoodsCategoryById(secondCategory.getParentId()); if (firestCategory != null) {//所有分类数据都得到之后放到request对象中供前端读取request.setAttribute("firstLevelCategories", firstLevelCategories); request.setAttribute("secondLevelCategories", secondLevelCategories); request.setAttribute("thirdLevelCategories", thirdLevelCategories); request.setAttribute("firstLevelCategoryId", firestCategory.getCategoryId()); request.setAttribute("secondLevelCategoryId", secondCategory.getCategoryId()); request.setAttribute("thirdLevelCategoryId", currentGoodsCategory.getCategoryId()); }}}}}if (newBeeMallGoods.getGoodsCategoryId() == 0) {//查询所有的一级分类List firstLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(0L), NewBeeMallCategoryLevelEnum.LEVEL_ONE.getLevel()); if (!CollectionUtils.isEmpty(firstLevelCategories)) {//查询一级分类列表中第一个实体的所有二级分类List secondLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(firstLevelCategories.get(0).getCategoryId()), NewBeeMallCategoryLevelEnum.LEVEL_TWO.getLevel()); if (!CollectionUtils.isEmpty(secondLevelCategories)) {//查询二级分类列表中第一个实体的所有三级分类List thirdLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(secondLevelCategories.get(0).getCategoryId()), NewBeeMallCategoryLevelEnum.LEVEL_THREE.getLevel()); request.setAttribute("firstLevelCategories", firstLevelCategories); request.setAttribute("secondLevelCategories", secondLevelCategories); request.setAttribute("thirdLevelCategories", thirdLevelCategories); }}}request.setAttribute("goods", newBeeMallGoods); request.setAttribute("path", "goods-edit"); return "admin/newbee_mall_goods_edit"; } /*** 列表*/@RequestMapping(value = "https://www.it610.com/goods/list", method = RequestMethod.GET)@ResponseBodypublic Result list(@RequestParam Map params) {if (StringUtils.isEmpty(params.get("page")) || StringUtils.isEmpty(params.get("limit"))) {return ResultGenerator.genFailResult("参数异常!"); }PageQueryUtil pageUtil = new PageQueryUtil(params); return ResultGenerator.genSuccessResult(newBeeMallGoodsService.getNewBeeMallGoodsPage(pageUtil)); } /*** 添加*/@RequestMapping(value = "https://www.it610.com/goods/save", method = RequestMethod.POST)@ResponseBodypublic Result save(@RequestBody NewBeeMallGoods newBeeMallGoods) {if (StringUtils.isEmpty(newBeeMallGoods.getGoodsName())|| StringUtils.isEmpty(newBeeMallGoods.getGoodsIntro())|| StringUtils.isEmpty(newBeeMallGoods.getTag())|| Objects.isNull(newBeeMallGoods.getOriginalPrice())|| Objects.isNull(newBeeMallGoods.getGoodsCategoryId())|| Objects.isNull(newBeeMallGoods.getSellingPrice())|| Objects.isNull(newBeeMallGoods.getStockNum())|| Objects.isNull(newBeeMallGoods.getGoodsSellStatus())|| StringUtils.isEmpty(newBeeMallGoods.getGoodsCoverImg())|| StringUtils.isEmpty(newBeeMallGoods.getGoodsDetailContent())) {return ResultGenerator.genFailResult("参数异常!"); }String result = newBeeMallGoodsService.saveNewBeeMallGoods(newBeeMallGoods); if (ServiceResultEnum.SUCCESS.getResult().equals(result)) {return ResultGenerator.genSuccessResult(); } else {return ResultGenerator.genFailResult(result); }} /*** 修改*/@RequestMapping(value = "https://www.it610.com/goods/update", method = RequestMethod.POST)@ResponseBodypublic Result update(@RequestBody NewBeeMallGoods newBeeMallGoods) {if (Objects.isNull(newBeeMallGoods.getGoodsId())|| StringUtils.isEmpty(newBeeMallGoods.getGoodsName())|| StringUtils.isEmpty(newBeeMallGoods.getGoodsIntro())|| StringUtils.isEmpty(newBeeMallGoods.getTag())|| Objects.isNull(newBeeMallGoods.getOriginalPrice())|| Objects.isNull(newBeeMallGoods.getSellingPrice())|| Objects.isNull(newBeeMallGoods.getGoodsCategoryId())|| Objects.isNull(newBeeMallGoods.getStockNum())|| Objects.isNull(newBeeMallGoods.getGoodsSellStatus())|| StringUtils.isEmpty(newBeeMallGoods.getGoodsCoverImg())|| StringUtils.isEmpty(newBeeMallGoods.getGoodsDetailContent())) {return ResultGenerator.genFailResult("参数异常!"); }String result = newBeeMallGoodsService.updateNewBeeMallGoods(newBeeMallGoods); if (ServiceResultEnum.SUCCESS.getResult().equals(result)) {return ResultGenerator.genSuccessResult(); } else {return ResultGenerator.genFailResult(result); }} /*** 详情*/@GetMapping("/goods/info/{id}")@ResponseBodypublic Result info(@PathVariable("id") Long id) {NewBeeMallGoods goods = newBeeMallGoodsService.getNewBeeMallGoodsById(id); if (goods == null) {return ResultGenerator.genFailResult(ServiceResultEnum.DATA_NOT_EXIST.getResult()); }return ResultGenerator.genSuccessResult(goods); } /*** 批量修改销售状态*/@RequestMapping(value = "https://www.it610.com/goods/status/{sellStatus}", method = RequestMethod.PUT)@ResponseBodypublic Result delete(@RequestBody Long[] ids, @PathVariable("sellStatus") int sellStatus) {if (ids.length < 1) {return ResultGenerator.genFailResult("参数异常!"); }if (sellStatus != Constants.SELL_STATUS_UP && sellStatus != Constants.SELL_STATUS_DOWN) {return ResultGenerator.genFailResult("状态异常!"); }if (newBeeMallGoodsService.batchUpdateSellStatus(ids, sellStatus)) {return ResultGenerator.genSuccessResult(); } else {return ResultGenerator.genFailResult("修改失败"); }} }
商品分类控制器:
/** * @author yy */@Controller@RequestMapping("/admin")public class NewBeeMallGoodsCategoryController { @Resourceprivate NewBeeMallCategoryService newBeeMallCategoryService; @GetMapping("/categories")public String categoriesPage(HttpServletRequest request, @RequestParam("categoryLevel") Byte categoryLevel, @RequestParam("parentId") Long parentId, @RequestParam("backParentId") Long backParentId) {if (categoryLevel == null || categoryLevel < 1 || categoryLevel > 3) {return "error/error_5xx"; }request.setAttribute("path", "newbee_mall_category"); request.setAttribute("parentId", parentId); request.setAttribute("backParentId", backParentId); request.setAttribute("categoryLevel", categoryLevel); return "admin/newbee_mall_category"; } /*** 列表*/@RequestMapping(value = "https://www.it610.com/categories/list", method = RequestMethod.GET)@ResponseBodypublic Result list(@RequestParam Map params) {if (StringUtils.isEmpty(params.get("page")) || StringUtils.isEmpty(params.get("limit"))) {return ResultGenerator.genFailResult("参数异常!"); }PageQueryUtil pageUtil = new PageQueryUtil(params); return ResultGenerator.genSuccessResult(newBeeMallCategoryService.getCategorisPage(pageUtil)); } /*** 列表*/@RequestMapping(value = "https://www.it610.com/categories/listForSelect", method = RequestMethod.GET)@ResponseBodypublic Result listForSelect(@RequestParam("categoryId") Long categoryId) {if (categoryId == null || categoryId < 1) {return ResultGenerator.genFailResult("缺少参数!"); }GoodsCategory category = newBeeMallCategoryService.getGoodsCategoryById(categoryId); //既不是一级分类也不是二级分类则为不返回数据if (category == null || category.getCategoryLevel() == NewBeeMallCategoryLevelEnum.LEVEL_THREE.getLevel()) {return ResultGenerator.genFailResult("参数异常!"); }Map categoryResult = new HashMap(2); if (category.getCategoryLevel() == NewBeeMallCategoryLevelEnum.LEVEL_ONE.getLevel()) {//如果是一级分类则返回当前一级分类下的所有二级分类,以及二级分类列表中第一条数据下的所有三级分类列表//查询一级分类列表中第一个实体的所有二级分类ListsecondLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(categoryId), NewBeeMallCategoryLevelEnum.LEVEL_TWO.getLevel()); if (!CollectionUtils.isEmpty(secondLevelCategories)) {//查询二级分类列表中第一个实体的所有三级分类List thirdLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(secondLevelCategories.get(0).getCategoryId()), NewBeeMallCategoryLevelEnum.LEVEL_THREE.getLevel()); categoryResult.put("secondLevelCategories", secondLevelCategories); categoryResult.put("thirdLevelCategories", thirdLevelCategories); }}if (category.getCategoryLevel() == NewBeeMallCategoryLevelEnum.LEVEL_TWO.getLevel()) {//如果是二级分类则返回当前分类下的所有三级分类列表List thirdLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(categoryId), NewBeeMallCategoryLevelEnum.LEVEL_THREE.getLevel()); categoryResult.put("thirdLevelCategories", thirdLevelCategories); }return ResultGenerator.genSuccessResult(categoryResult); } /*** 添加*/@RequestMapping(value = "https://www.it610.com/categories/save", method = RequestMethod.POST)@ResponseBodypublic Result save(@RequestBody GoodsCategory goodsCategory) {if (Objects.isNull(goodsCategory.getCategoryLevel())|| StringUtils.isEmpty(goodsCategory.getCategoryName())|| Objects.isNull(goodsCategory.getParentId())|| Objects.isNull(goodsCategory.getCategoryRank())) {return ResultGenerator.genFailResult("参数异常!"); }String result = newBeeMallCategoryService.saveCategory(goodsCategory); if (ServiceResultEnum.SUCCESS.getResult().equals(result)) {return ResultGenerator.genSuccessResult(); } else {return ResultGenerator.genFailResult(result); }} /*** 修改*/@RequestMapping(value = "https://www.it610.com/categories/update", method = RequestMethod.POST)@ResponseBodypublic Result update(@RequestBody GoodsCategory goodsCategory) {if (Objects.isNull(goodsCategory.getCategoryId())|| Objects.isNull(goodsCategory.getCategoryLevel())|| StringUtils.isEmpty(goodsCategory.getCategoryName())|| Objects.isNull(goodsCategory.getParentId())|| Objects.isNull(goodsCategory.getCategoryRank())) {return ResultGenerator.genFailResult("参数异常!"); }String result = newBeeMallCategoryService.updateGoodsCategory(goodsCategory); if (ServiceResultEnum.SUCCESS.getResult().equals(result)) {return ResultGenerator.genSuccessResult(); } else {return ResultGenerator.genFailResult(result); }} /*** 详情*/@GetMapping("/categories/info/{id}")@ResponseBodypublic Result info(@PathVariable("id") Long id) {GoodsCategory goodsCategory = newBeeMallCategoryService.getGoodsCategoryById(id); if (goodsCategory == null) {return ResultGenerator.genFailResult("未查询到数据"); }return ResultGenerator.genSuccessResult(goodsCategory); } /*** 分类删除*/@RequestMapping(value = "https://www.it610.com/categories/delete", method = RequestMethod.POST)@ResponseBodypublic Result delete(@RequestBody Integer[] ids) {if (ids.length < 1) {return ResultGenerator.genFailResult("参数异常!"); }if (newBeeMallCategoryService.deleteBatch(ids)) {return ResultGenerator.genSuccessResult(); } else {return ResultGenerator.genFailResult("删除失败"); }} }
到此这篇关于Java女装商城系统的实现流程的文章就介绍到这了,更多相关Java 女装商城系统内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
推荐阅读
- JAVA(抽象类与接口的区别&重载与重写&内存泄漏)
- 事件代理
- Java|Java OpenCV图像处理之SIFT角点检测详解
- java中如何实现重建二叉树
- 数组常用方法一
- 【Hadoop踩雷】Mac下安装Hadoop3以及Java版本问题
- Java|Java基础——数组
- RxJava|RxJava 在Android项目中的使用(一)
- java之static、static|java之static、static final、final的区别与应用
- Java基础-高级特性-枚举实现状态机