how2j.cn

-->
下载区
文件名 文件大小
请先登录 1m
增值内容 1m
1m

解压rar如果失败,请用5.21版本或者更高版本的winrar

点击下载 winrar5.21
步骤 1 : 先运行,看到效果,再学习   
步骤 2 : 模仿和排错   
步骤 3 : 购物车页面操作   
步骤 4 : 调整订单数量   
步骤 5 : 删除订单项   
步骤 6 : 提交到结算页面   

步骤 1 :

先运行,看到效果,再学习

edit
增值内容,请先登录
完整的SSM模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSM一整套技术栈, 从无到有涵盖全部126个知识点,560个开发步骤, 充实SSM项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
增值内容,请先登录
完整的SSM模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSM一整套技术栈, 从无到有涵盖全部126个知识点,560个开发步骤, 充实SSM项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
步骤 3 :

购物车页面操作

edit
增值内容,请先登录
完整的SSM模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSM一整套技术栈, 从无到有涵盖全部126个知识点,560个开发步骤, 充实SSM项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
购物车页面操作
步骤 4 :

调整订单数量

edit
增值内容,请先登录
完整的SSM模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSM一整套技术栈, 从无到有涵盖全部126个知识点,560个开发步骤, 充实SSM项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
调整订单数量
var page = "forechangeOrderItem"; $.post( page, {"pid":pid,"number":num}, function(result){ if("success"!=result){ location.href="loginPage"; } } );
@RequestMapping("forechangeOrderItem") @ResponseBody public String changeOrderItem( Model model,HttpSession session, int pid, int number) { User user =(User) session.getAttribute("user"); if(null==user) return "fail"; List<OrderItem> ois = orderItemService.listByUser(user.getId()); for (OrderItem oi : ois) { if(oi.getProduct().getId().intValue()==pid){ oi.setNumber(number); orderItemService.update(oi); break; } } return "success"; } }
package com.how2java.tmall.controller; import com.github.pagehelper.PageHelper; import com.how2java.tmall.pojo.*; import com.how2java.tmall.service.*; import comparator.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.util.HtmlUtils; import javax.servlet.http.HttpSession; import java.util.ArrayList; import java.util.Collections; import java.util.List; @Controller @RequestMapping("") public class ForeController { @Autowired CategoryService categoryService; @Autowired ProductService productService; @Autowired UserService userService; @Autowired ProductImageService productImageService; @Autowired PropertyValueService propertyValueService; @Autowired OrderService orderService; @Autowired OrderItemService orderItemService; @Autowired ReviewService reviewService; @RequestMapping("forehome") public String home(Model model) { List<Category> cs= categoryService.list(); productService.fill(cs); productService.fillByRow(cs); model.addAttribute("cs", cs); return "fore/home"; } @RequestMapping("foreregister") public String register(Model model,User user) { String name = user.getName(); name = HtmlUtils.htmlEscape(name); user.setName(name); boolean exist = userService.isExist(name); if(exist){ String m ="用户名已经被使用,不能使用"; model.addAttribute("msg", m); return "fore/register"; } userService.add(user); return "redirect:registerSuccessPage"; } @RequestMapping("forelogin") public String login(@RequestParam("name") String name, @RequestParam("password") String password, Model model, HttpSession session) { name = HtmlUtils.htmlEscape(name); User user = userService.get(name,password); if(null==user){ model.addAttribute("msg", "账号密码错误"); return "fore/login"; } session.setAttribute("user", user); return "redirect:forehome"; } @RequestMapping("forelogout") public String logout( HttpSession session) { session.removeAttribute("user"); return "redirect:forehome"; } @RequestMapping("foreproduct") public String product( int pid, Model model) { Product p = productService.get(pid); List<ProductImage> productSingleImages = productImageService.list(p.getId(), ProductImageService.type_single); List<ProductImage> productDetailImages = productImageService.list(p.getId(), ProductImageService.type_detail); p.setProductSingleImages(productSingleImages); p.setProductDetailImages(productDetailImages); List<PropertyValue> pvs = propertyValueService.list(p.getId()); List<Review> reviews = reviewService.list(p.getId()); productService.setSaleAndReviewNumber(p); model.addAttribute("reviews", reviews); model.addAttribute("p", p); model.addAttribute("pvs", pvs); return "fore/product"; } @RequestMapping("forecheckLogin") @ResponseBody public String checkLogin( HttpSession session) { User user =(User) session.getAttribute("user"); if(null!=user) return "success"; return "fail"; } @RequestMapping("foreloginAjax") @ResponseBody public String loginAjax(@RequestParam("name") String name, @RequestParam("password") String password,HttpSession session) { name = HtmlUtils.htmlEscape(name); User user = userService.get(name,password); if(null==user){ return "fail"; } session.setAttribute("user", user); return "success"; } @RequestMapping("forecategory") public String category(int cid,String sort, Model model) { Category c = categoryService.get(cid); productService.fill(c); productService.setSaleAndReviewNumber(c.getProducts()); if(null!=sort){ switch(sort){ case "review": Collections.sort(c.getProducts(),new ProductReviewComparator()); break; case "date" : Collections.sort(c.getProducts(),new ProductDateComparator()); break; case "saleCount" : Collections.sort(c.getProducts(),new ProductSaleCountComparator()); break; case "price": Collections.sort(c.getProducts(),new ProductPriceComparator()); break; case "all": Collections.sort(c.getProducts(),new ProductAllComparator()); break; } } model.addAttribute("c", c); return "fore/category"; } @RequestMapping("foresearch") public String search( String keyword,Model model){ PageHelper.offsetPage(0,20); List<Product> ps= productService.search(keyword); productService.setSaleAndReviewNumber(ps); model.addAttribute("ps",ps); return "fore/searchResult"; } @RequestMapping("forebuyone") public String buyone(int pid, int num, HttpSession session) { Product p = productService.get(pid); int oiid = 0; User user =(User) session.getAttribute("user"); boolean found = false; List<OrderItem> ois = orderItemService.listByUser(user.getId()); for (OrderItem oi : ois) { if(oi.getProduct().getId().intValue()==p.getId().intValue()){ oi.setNumber(oi.getNumber()+num); orderItemService.update(oi); found = true; oiid = oi.getId(); break; } } if(!found){ OrderItem oi = new OrderItem(); oi.setUid(user.getId()); oi.setNumber(num); oi.setPid(pid); orderItemService.add(oi); oiid = oi.getId(); } return "redirect:forebuy?oiid="+oiid; } @RequestMapping("forebuy") public String buy( Model model,String[] oiid,HttpSession session){ List<OrderItem> ois = new ArrayList<>(); float total = 0; for (String strid : oiid) { int id = Integer.parseInt(strid); OrderItem oi= orderItemService.get(id); total +=oi.getProduct().getPromotePrice()*oi.getNumber(); ois.add(oi); } session.setAttribute("ois", ois); model.addAttribute("total", total); return "fore/buy"; } @RequestMapping("foreaddCart") @ResponseBody public String addCart(int pid, int num, Model model,HttpSession session) { Product p = productService.get(pid); User user =(User) session.getAttribute("user"); boolean found = false; List<OrderItem> ois = orderItemService.listByUser(user.getId()); for (OrderItem oi : ois) { if(oi.getProduct().getId().intValue()==p.getId().intValue()){ oi.setNumber(oi.getNumber()+num); orderItemService.update(oi); found = true; break; } } if(!found){ OrderItem oi = new OrderItem(); oi.setUid(user.getId()); oi.setNumber(num); oi.setPid(pid); orderItemService.add(oi); } return "success"; } @RequestMapping("forecart") public String cart( Model model,HttpSession session) { User user =(User) session.getAttribute("user"); List<OrderItem> ois = orderItemService.listByUser(user.getId()); model.addAttribute("ois", ois); return "fore/cart"; } @RequestMapping("forechangeOrderItem") @ResponseBody public String changeOrderItem( Model model,HttpSession session, int pid, int number) { User user =(User) session.getAttribute("user"); if(null==user) return "fail"; List<OrderItem> ois = orderItemService.listByUser(user.getId()); for (OrderItem oi : ois) { if(oi.getProduct().getId().intValue()==pid){ oi.setNumber(number); orderItemService.update(oi); break; } } return "success"; } }
增值内容,请先登录
完整的SSM模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSM一整套技术栈, 从无到有涵盖全部126个知识点,560个开发步骤, 充实SSM项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
删除订单项
var page="foredeleteOrderItem"; $.post( page, {"oiid":deleteOrderItemid}, function(result){ if("success"==result){ $("tr.cartProductItemTR[oiid="+deleteOrderItemid+"]").hide(); } else{ location.href="loginPage"; } } );
@RequestMapping("foredeleteOrderItem") @ResponseBody public String deleteOrderItem( Model model,HttpSession session,int oiid){ User user =(User) session.getAttribute("user"); if(null==user) return "fail"; orderItemService.delete(oiid); return "success"; } }
package com.how2java.tmall.controller; import com.github.pagehelper.PageHelper; import com.how2java.tmall.pojo.*; import com.how2java.tmall.service.*; import comparator.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.util.HtmlUtils; import javax.servlet.http.HttpSession; import java.util.ArrayList; import java.util.Collections; import java.util.List; @Controller @RequestMapping("") public class ForeController { @Autowired CategoryService categoryService; @Autowired ProductService productService; @Autowired UserService userService; @Autowired ProductImageService productImageService; @Autowired PropertyValueService propertyValueService; @Autowired OrderService orderService; @Autowired OrderItemService orderItemService; @Autowired ReviewService reviewService; @RequestMapping("forehome") public String home(Model model) { List<Category> cs= categoryService.list(); productService.fill(cs); productService.fillByRow(cs); model.addAttribute("cs", cs); return "fore/home"; } @RequestMapping("foreregister") public String register(Model model,User user) { String name = user.getName(); name = HtmlUtils.htmlEscape(name); user.setName(name); boolean exist = userService.isExist(name); if(exist){ String m ="用户名已经被使用,不能使用"; model.addAttribute("msg", m); return "fore/register"; } userService.add(user); return "redirect:registerSuccessPage"; } @RequestMapping("forelogin") public String login(@RequestParam("name") String name, @RequestParam("password") String password, Model model, HttpSession session) { name = HtmlUtils.htmlEscape(name); User user = userService.get(name,password); if(null==user){ model.addAttribute("msg", "账号密码错误"); return "fore/login"; } session.setAttribute("user", user); return "redirect:forehome"; } @RequestMapping("forelogout") public String logout( HttpSession session) { session.removeAttribute("user"); return "redirect:forehome"; } @RequestMapping("foreproduct") public String product( int pid, Model model) { Product p = productService.get(pid); List<ProductImage> productSingleImages = productImageService.list(p.getId(), ProductImageService.type_single); List<ProductImage> productDetailImages = productImageService.list(p.getId(), ProductImageService.type_detail); p.setProductSingleImages(productSingleImages); p.setProductDetailImages(productDetailImages); List<PropertyValue> pvs = propertyValueService.list(p.getId()); List<Review> reviews = reviewService.list(p.getId()); productService.setSaleAndReviewNumber(p); model.addAttribute("reviews", reviews); model.addAttribute("p", p); model.addAttribute("pvs", pvs); return "fore/product"; } @RequestMapping("forecheckLogin") @ResponseBody public String checkLogin( HttpSession session) { User user =(User) session.getAttribute("user"); if(null!=user) return "success"; return "fail"; } @RequestMapping("foreloginAjax") @ResponseBody public String loginAjax(@RequestParam("name") String name, @RequestParam("password") String password,HttpSession session) { name = HtmlUtils.htmlEscape(name); User user = userService.get(name,password); if(null==user){ return "fail"; } session.setAttribute("user", user); return "success"; } @RequestMapping("forecategory") public String category(int cid,String sort, Model model) { Category c = categoryService.get(cid); productService.fill(c); productService.setSaleAndReviewNumber(c.getProducts()); if(null!=sort){ switch(sort){ case "review": Collections.sort(c.getProducts(),new ProductReviewComparator()); break; case "date" : Collections.sort(c.getProducts(),new ProductDateComparator()); break; case "saleCount" : Collections.sort(c.getProducts(),new ProductSaleCountComparator()); break; case "price": Collections.sort(c.getProducts(),new ProductPriceComparator()); break; case "all": Collections.sort(c.getProducts(),new ProductAllComparator()); break; } } model.addAttribute("c", c); return "fore/category"; } @RequestMapping("foresearch") public String search( String keyword,Model model){ PageHelper.offsetPage(0,20); List<Product> ps= productService.search(keyword); productService.setSaleAndReviewNumber(ps); model.addAttribute("ps",ps); return "fore/searchResult"; } @RequestMapping("forebuyone") public String buyone(int pid, int num, HttpSession session) { Product p = productService.get(pid); int oiid = 0; User user =(User) session.getAttribute("user"); boolean found = false; List<OrderItem> ois = orderItemService.listByUser(user.getId()); for (OrderItem oi : ois) { if(oi.getProduct().getId().intValue()==p.getId().intValue()){ oi.setNumber(oi.getNumber()+num); orderItemService.update(oi); found = true; oiid = oi.getId(); break; } } if(!found){ OrderItem oi = new OrderItem(); oi.setUid(user.getId()); oi.setNumber(num); oi.setPid(pid); orderItemService.add(oi); oiid = oi.getId(); } return "redirect:forebuy?oiid="+oiid; } @RequestMapping("forebuy") public String buy( Model model,String[] oiid,HttpSession session){ List<OrderItem> ois = new ArrayList<>(); float total = 0; for (String strid : oiid) { int id = Integer.parseInt(strid); OrderItem oi= orderItemService.get(id); total +=oi.getProduct().getPromotePrice()*oi.getNumber(); ois.add(oi); } session.setAttribute("ois", ois); model.addAttribute("total", total); return "fore/buy"; } @RequestMapping("foreaddCart") @ResponseBody public String addCart(int pid, int num, Model model,HttpSession session) { Product p = productService.get(pid); User user =(User) session.getAttribute("user"); boolean found = false; List<OrderItem> ois = orderItemService.listByUser(user.getId()); for (OrderItem oi : ois) { if(oi.getProduct().getId().intValue()==p.getId().intValue()){ oi.setNumber(oi.getNumber()+num); orderItemService.update(oi); found = true; break; } } if(!found){ OrderItem oi = new OrderItem(); oi.setUid(user.getId()); oi.setNumber(num); oi.setPid(pid); orderItemService.add(oi); } return "success"; } @RequestMapping("forecart") public String cart( Model model,HttpSession session) { User user =(User) session.getAttribute("user"); List<OrderItem> ois = orderItemService.listByUser(user.getId()); model.addAttribute("ois", ois); return "fore/cart"; } @RequestMapping("forechangeOrderItem") @ResponseBody public String changeOrderItem( Model model,HttpSession session, int pid, int number) { User user =(User) session.getAttribute("user"); if(null==user) return "fail"; List<OrderItem> ois = orderItemService.listByUser(user.getId()); for (OrderItem oi : ois) { if(oi.getProduct().getId().intValue()==pid){ oi.setNumber(number); orderItemService.update(oi); break; } } return "success"; } @RequestMapping("foredeleteOrderItem") @ResponseBody public String deleteOrderItem( Model model,HttpSession session,int oiid){ User user =(User) session.getAttribute("user"); if(null==user) return "fail"; orderItemService.delete(oiid); return "success"; } }
步骤 6 :

提交到结算页面

edit
增值内容,请先登录
完整的SSM模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSM一整套技术栈, 从无到有涵盖全部126个知识点,560个开发步骤, 充实SSM项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
提交到结算页面


HOW2J公众号,关注后实时获知最新的教程和优惠活动,谢谢。


问答区域    
2021-08-02 调整数量的时候 不断的异步请求 改变num 和数据库交互是不是有点浪费资源,点结算的时候统一提交 会不会好一点
vcaml

rt




2 个答案

lwb5070074
答案时间:2022-04-19
应该不会丢失信息吧,选好了再最终一起提交不好吗?

how2j
答案时间:2021-08-21
结算才提交,那么中途调整的信息就丢失了呀



回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
答案 或者 代码至少填写一项, 如果是自己有问题,请重新提问,否则站长有可能看不到




2021-03-17 oiid是啥
偏爱余人

购物车那里 的 oiid是什么




1 个答案

how2j
答案时间:2021-03-20
orderitem 的id



回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
答案 或者 代码至少填写一项, 如果是自己有问题,请重新提问,否则站长有可能看不到




2020-08-31 有个严重的安全问题!!
2019-10-08 一个小问题
2019-06-03 不是进入购物车之前必须要登陆吗,怎么修改数量之前还要判断是否已登录


提问太多,页面渲染太慢,为了加快渲染速度,本页最多只显示几条提问。还有 6 条以前的提问,请 点击查看

提问之前请登陆
提问已经提交成功,正在审核。 请于 我的提问 处查看提问记录,谢谢
关于 实践项目-天猫整站SSM-购物车页面操作 的提问

尽量提供截图代码异常信息,有助于分析和解决问题。 也可进本站QQ群交流: 578362961
提问尽量提供完整的代码,环境描述,越是有利于问题的重现,您的问题越能更快得到解答。
对教程中代码有疑问,请提供是哪个步骤,哪一行有疑问,这样便于快速定位问题,提高问题得到解答的速度
在已经存在的几千个提问里,有相当大的比例,是因为使用了和站长不同版本的开发环境导致的,比如 jdk, eclpise, idea, mysql,tomcat 等等软件的版本不一致。
请使用和站长一样的版本,可以节约自己大量的学习时间。 站长把教学中用的软件版本整理了,都统一放在了这里, 方便大家下载: https://how2j.cn/k/helloworld/helloworld-version/1718.html

上传截图