您好,登錄后才能下訂單哦!
這篇文章將為大家詳細講解有關Java如何實現女裝商城系統,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
javaweb 網上商城系統,前臺+后臺管理,用戶注冊,登錄,上哦展示,分組展示,搜索,收貨地址管理,購物車管理,添加,購買,個人信息修改。訂單查詢等等,后臺商品管理,分類管理,庫存管理,訂單管理,用戶管理,信息修改等等.
環境配置: Jdk1.8 + Tomcats . 5 + mysql + Eclispe ( IntelliJ IDEA ,Eclispe , MyEclispe , sts 都支持)
項目技術: JSP + Spring + SpringMVC + MyBatis + html + cSS + Javascript + JQuery + Ajax + layui + maven 等等。
/** * 后臺管理-主頁 */ @Controller public 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 = "admin", method = RequestMethod.GET) public String goToPage(HttpSession session, Map<String, Object> 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 = "admin/home", method = RequestMethod.GET) public String goToPageByAjax(HttpSession session, Map<String, Object> 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 = "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("從數據庫中獲取統計的訂單集合數據"); List<OrderGroup> orderGroupList = 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 { @Resource private NewBeeMallGoodsService newBeeMallGoodsService; @Resource private 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"); //查詢所有的一級分類 List<GoodsCategory> firstLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(0L), NewBeeMallCategoryLevelEnum.LEVEL_ONE.getLevel()); if (!CollectionUtils.isEmpty(firstLevelCategories)) { //查詢一級分類列表中第一個實體的所有二級分類 List<GoodsCategory> secondLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(firstLevelCategories.get(0).getCategoryId()), NewBeeMallCategoryLevelEnum.LEVEL_TWO.getLevel()); if (!CollectionUtils.isEmpty(secondLevelCategories)) { //查詢二級分類列表中第一個實體的所有三級分類 List<GoodsCategory> 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<GoodsCategory> firstLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(0L), NewBeeMallCategoryLevelEnum.LEVEL_ONE.getLevel()); //根據parentId查詢當前parentId下所有的三級分類 List<GoodsCategory> thirdLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(currentGoodsCategory.getParentId()), NewBeeMallCategoryLevelEnum.LEVEL_THREE.getLevel()); //查詢當前三級分類的父級二級分類 GoodsCategory secondCategory = newBeeMallCategoryService.getGoodsCategoryById(currentGoodsCategory.getParentId()); if (secondCategory != null) { //根據parentId查詢當前parentId下所有的二級分類 List<GoodsCategory> 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<GoodsCategory> firstLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(0L), NewBeeMallCategoryLevelEnum.LEVEL_ONE.getLevel()); if (!CollectionUtils.isEmpty(firstLevelCategories)) { //查詢一級分類列表中第一個實體的所有二級分類 List<GoodsCategory> secondLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(firstLevelCategories.get(0).getCategoryId()), NewBeeMallCategoryLevelEnum.LEVEL_TWO.getLevel()); if (!CollectionUtils.isEmpty(secondLevelCategories)) { //查詢二級分類列表中第一個實體的所有三級分類 List<GoodsCategory> 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 = "/goods/list", method = RequestMethod.GET) @ResponseBody public Result list(@RequestParam Map<String, Object> 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 = "/goods/save", method = RequestMethod.POST) @ResponseBody public 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 = "/goods/update", method = RequestMethod.POST) @ResponseBody public 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}") @ResponseBody public 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 = "/goods/status/{sellStatus}", method = RequestMethod.PUT) @ResponseBody public 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 { @Resource private 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 = "/categories/list", method = RequestMethod.GET) @ResponseBody public Result list(@RequestParam Map<String, Object> 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 = "/categories/listForSelect", method = RequestMethod.GET) @ResponseBody public 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()) { //如果是一級分類則返回當前一級分類下的所有二級分類,以及二級分類列表中第一條數據下的所有三級分類列表 //查詢一級分類列表中第一個實體的所有二級分類 List<GoodsCategory> secondLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(categoryId), NewBeeMallCategoryLevelEnum.LEVEL_TWO.getLevel()); if (!CollectionUtils.isEmpty(secondLevelCategories)) { //查詢二級分類列表中第一個實體的所有三級分類 List<GoodsCategory> 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<GoodsCategory> thirdLevelCategories = newBeeMallCategoryService.selectByLevelAndParentIdsAndNumber(Collections.singletonList(categoryId), NewBeeMallCategoryLevelEnum.LEVEL_THREE.getLevel()); categoryResult.put("thirdLevelCategories", thirdLevelCategories); } return ResultGenerator.genSuccessResult(categoryResult); } /** * 添加 */ @RequestMapping(value = "/categories/save", method = RequestMethod.POST) @ResponseBody public 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 = "/categories/update", method = RequestMethod.POST) @ResponseBody public 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}") @ResponseBody public Result info(@PathVariable("id") Long id) { GoodsCategory goodsCategory = newBeeMallCategoryService.getGoodsCategoryById(id); if (goodsCategory == null) { return ResultGenerator.genFailResult("未查詢到數據"); } return ResultGenerator.genSuccessResult(goodsCategory); } /** * 分類刪除 */ @RequestMapping(value = "/categories/delete", method = RequestMethod.POST) @ResponseBody public Result delete(@RequestBody Integer[] ids) { if (ids.length < 1) { return ResultGenerator.genFailResult("參數異常!"); } if (newBeeMallCategoryService.deleteBatch(ids)) { return ResultGenerator.genSuccessResult(); } else { return ResultGenerator.genFailResult("刪除失敗"); } } }
關于“Java如何實現女裝商城系統”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。