Java 實戰項目之傢居購物商城系統詳解流程
一、項目簡述
功能: Java Web精品項目源碼,傢居商城分類展示,商品展示, 商品下單,購物車,個人中心,後臺管理,用戶管理,商品管理,分類管理等等。
二、項目運行
環境配置: Jdk1.8 + Tomcat8.5 + mysql + Eclispe (IntelliJ IDEA,Eclispe,MyEclispe,Sts 都支持)
項目技術: Jdbc+ Servlert + html+ css + JavaScript + JQuery + Ajax + Fileupload
打開訂單列表頁面代碼:
@Controller @RequestMapping("/order") public class OrderController { @Autowired private OrderService orderService; /** * 打開訂單列表頁面 * * @return */ @RequestMapping("/toList.html") public String toOrderList() { return "mall/order/list"; } /** * 查詢用戶訂單列表 * * @param request * @return */ @RequestMapping("/list.do") @ResponseBody public ResultBean<List<Order>> listData(HttpServletRequest request) { List<Order> orders = orderService.findUserOrder(request); return new ResultBean<>(orders); } /** * 查詢訂單詳情 * * @param orderId * @return */ @RequestMapping("/getDetail.do") @ResponseBody public ResultBean<List<OrderItem>> getDetail(int orderId) { List<OrderItem> orderItems = orderService.findItems(orderId); return new ResultBean<>(orderItems); } /** * 提交訂單 * * @param name * @param phone * @param addr * @param request * @param response */ @RequestMapping("/submit.do") public void submit(String name, String phone, String addr, HttpServletRequest request, HttpServletResponse response) throws Exception { orderService.submit(name, phone, addr, request, response); } /** * 支付方法 * * @param orderId */ @RequestMapping("pay.do") @ResponseBody public ResultBean<Boolean> pay(int orderId, HttpServletResponse response) throws IOException { orderService.pay(orderId); return new ResultBean<>(true); } /** * 確認收貨 * @param orderId * @param response * @return * @throws IOException */ @RequestMapping("receive.do") @ResponseBody public ResultBean<Boolean> receive(int orderId, HttpServletResponse response) throws IOException { orderService.receive(orderId); return new ResultBean<>(true); } }
商品信息操作代碼:
@Controller @RequestMapping("/product") public class ProductController { @Autowired private ProductService productService; @Autowired private ClassificationService classificationService; @Autowired private ShopCartService shopCartService; /** * 獲取商品信息 * * @param id * @return */ @RequestMapping("/get.do") public ResultBean<Product> getProduct(int id) { Product product = productService.findById(id); return new ResultBean<>(product); } /** * 打開商品詳情頁面 * * @param id * @param map * @return */ @RequestMapping("/get.html") public String toProductPage(int id, Map<String, Object> map) { Product product = productService.findById(id); map.put("product", product); return "mall/product/info"; } /** * 查找熱門商品 * * @return */ @ResponseBody @RequestMapping("/hot.do") public ResultBean<List<Product>> getHotProduct() { List<Product> products = productService.findHotProduct(); return new ResultBean<>(products); } /** * 查找最新商品 * * @param pageNo * @param pageSize * @return */ @ResponseBody @RequestMapping("/new.do") public ResultBean<List<Product>> getNewProduct(int pageNo, int pageSize) { Pageable pageable = new PageRequest(pageNo, pageSize); List<Product> products = productService.findNewProduct(pageable); return new ResultBean<>(products); } /** * 打開分類查看商品頁面 * * @return */ @RequestMapping("/category.html") public String toCatePage(int cid, Map<String, Object> map) { Classification classification = classificationService.findById(cid); map.put("category", classification); return "mall/product/category"; } @RequestMapping("/toCart.html") public String toCart(){ return "mall/product/cart"; } /** * 按一級分類查找商品 * * @param cid * @param pageNo * @param pageSize * @return */ @ResponseBody @RequestMapping("/category.do") public ResultBean<List<Product>> getCategoryProduct(int cid, int pageNo, int pageSize) { Pageable pageable = new PageRequest(pageNo, pageSize); List<Product> products = productService.findByCid(cid, pageable); return new ResultBean<>(products); } /** * 按二級分類查找商品 * * @param csId * @param pageNo * @param pageSize * @return */ @ResponseBody @RequestMapping("/categorySec.do") public ResultBean<List<Product>> getCategorySecProduct(int csId, int pageNo, int pageSize) { Pageable pageable = new PageRequest(pageNo, pageSize); List<Product> products = productService.findByCsid(csId, pageable); return new ResultBean<>(products); } /** * 根據一級分類查詢它所有的二級分類 * @param cid * @return */ @ResponseBody @RequestMapping("/getCategorySec.do") public ResultBean<List<Classification>> getCategorySec(int cid){ List<Classification> list = classificationService.findByParentId(cid); return new ResultBean<>(list); } /** * 加購物車 * * @param productId * @param request * @return */ @ResponseBody @RequestMapping("/addCart.do") public ResultBean<Boolean> addToCart(int productId, HttpServletRequest request) throws Exception { shopCartService.addCart(productId, request); return new ResultBean<>(true); } /** * 移除購物車 * * @param productId * @param request * @return */ @ResponseBody @RequestMapping("/delCart.do") public ResultBean<Boolean> delToCart(int productId, HttpServletRequest request) throws Exception { shopCartService.remove(productId, request); return new ResultBean<>(true); } /** * 查看購物車商品 * @param request * @return */ @ResponseBody @RequestMapping("/listCart.do") public ResultBean<List<OrderItem>> listCart(HttpServletRequest request) throws Exception { List<OrderItem> orderItems = shopCartService.listCart(request); return new ResultBean<>(orderItems); } }
以上就是Java 實戰項目之傢居購物商城系統詳解流程的詳細內容,更多關於Java 傢居購物商城系統的資料請關註WalkonNet其它相關文章!
推薦閱讀:
- 淺談@RequestParam 參數是否必須傳的問題
- Java 實戰練習之網上電商項目的實現
- 非常全面的Java SpringBoot點贊功能實現
- 使用Spring Data R2DBC +Postgres實現增刪改查功能
- 使用C#9中records作為強類型ID的實例教程