步骤 2 : 模仿和排错 步骤 3 : 界面效果 步骤 4 : ForeController.buy() 步骤 5 : buy.jsp 步骤 6 : buyPage.jsp
增值内容,请先登录
完整的SSM模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSM一整套技术栈, 从无到有涵盖全部126个知识点,560个开发步骤, 充实SSM项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
增值内容,请先登录
完整的SSM模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSM一整套技术栈, 从无到有涵盖全部126个知识点,560个开发步骤, 充实SSM项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
增值内容,请先登录
完整的SSM模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSM一整套技术栈, 从无到有涵盖全部126个知识点,560个开发步骤, 充实SSM项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
增值内容,请先登录
完整的SSM模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSM一整套技术栈, 从无到有涵盖全部126个知识点,560个开发步骤, 充实SSM项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
@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";
}
}
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";
}
}
增值内容,请先登录
完整的SSM模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSM一整套技术栈, 从无到有涵盖全部126个知识点,560个开发步骤, 充实SSM项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isELIgnored="false"%>
<%@include file="../include/fore/header.jsp"%>
<%@include file="../include/fore/top.jsp"%>
<%@include file="../include/fore/cart/buyPage.jsp"%>
<%@include file="../include/fore/footer.jsp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%> <%@include file="../include/fore/header.jsp"%> <%@include file="../include/fore/top.jsp"%> <%@include file="../include/fore/cart/buyPage.jsp"%> <%@include file="../include/fore/footer.jsp"%>
增值内容,请先登录
完整的SSM模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSM一整套技术栈, 从无到有涵盖全部126个知识点,560个开发步骤, 充实SSM项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" isELIgnored="false"%>
<div class="buyPageDiv">
<form action="forecreateOrder" method="post">
<div class="buyFlow">
<img class="pull-left" src="img/site/simpleLogo.png">
<img class="pull-right" src="img/site/buyflow.png">
<div style="clear:both"></div>
</div>
<div class="address">
<div class="addressTip">输入收货地址</div>
<div>
<table class="addressTable">
<tr>
<td class="firstColumn">详细地址<span class="redStar">*</span></td>
<td><textarea name="address" placeholder="建议您如实填写详细收货地址,例如接到名称,门牌好吗,楼层和房间号等信息"></textarea></td>
</tr>
<tr>
<td>邮政编码</td>
<td><input name="post" placeholder="如果您不清楚邮递区号,请填写000000" type="text"></td>
</tr>
<tr>
<td>收货人姓名<span class="redStar">*</span></td>
<td><input name="receiver" placeholder="长度不超过25个字符" type="text"></td>
</tr>
<tr>
<td>手机号码 <span class="redStar">*</span></td>
<td><input name="mobile" placeholder="请输入11位手机号码" type="text"></td>
</tr>
</table>
</div>
</div>
<div class="productList">
<div class="productListTip">确认订单信息</div>
<table class="productListTable">
<thead>
<tr>
<th colspan="2" class="productListTableFirstColumn">
<img class="tmallbuy" src="img/site/tmallbuy.png">
<a class="marketLink" href="#nowhere">店铺:天猫店铺</a>
<a class="wangwanglink" href="#nowhere"> <span class="wangwangGif"></span> </a>
</th>
<th>单价</th>
<th>数量</th>
<th>小计</th>
<th>配送方式</th>
</tr>
<tr class="rowborder">
<td colspan="2" ></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</thead>
<tbody class="productListTableTbody">
<c:forEach items="${ois}" var="oi" varStatus="st" >
<tr class="orderItemTR">
<td class="orderItemFirstTD"><img class="orderItemImg" src="img/productSingle_middle/${oi.product.firstProductImage.id}.jpg"></td>
<td class="orderItemProductInfo">
<a href="foreproduct?pid=${oi.product.id}" class="orderItemProductLink">
${oi.product.name}
</a>
<img src="img/site/creditcard.png" title="支持信用卡支付">
<img src="img/site/7day.png" title="消费者保障服务,承诺7天退货">
<img src="img/site/promise.png" title="消费者保障服务,承诺如实描述">
</td>
<td>
<span class="orderItemProductPrice">¥<fmt:formatNumber type="number" value="${oi.product.promotePrice}" minFractionDigits="2"/></span>
</td>
<td>
<span class="orderItemProductNumber">${oi.number}</span>
</td>
<td><span class="orderItemUnitSum">
¥<fmt:formatNumber type="number" value="${oi.number*oi.product.promotePrice}" minFractionDigits="2"/>
</span></td>
<c:if test="${st.count==1}">
<td rowspan="5" class="orderItemLastTD">
<label class="orderItemDeliveryLabel">
<input type="radio" value="" checked="checked">
普通配送
</label>
<select class="orderItemDeliverySelect" class="form-control">
<option>快递 免邮费</option>
</select>
</td>
</c:if>
</tr>
</c:forEach>
</tbody>
</table>
<div class="orderItemSumDiv">
<div class="pull-left">
<span class="leaveMessageText">给卖家留言:</span>
<span>
<img class="leaveMessageImg" src="img/site/leaveMessage.png">
</span>
<span class="leaveMessageTextareaSpan">
<textarea name="userMessage" class="leaveMessageTextarea"></textarea>
<div>
<span>还可以输入200个字符</span>
</div>
</span>
</div>
<span class="pull-right">店铺合计(含运费): ¥<fmt:formatNumber type="number" value="${total}" minFractionDigits="2"/></span>
</div>
</div>
<div class="orderItemTotalSumDiv">
<div class="pull-right">
<span>实付款:</span>
<span class="orderItemTotalSumSpan">¥<fmt:formatNumber type="number" value="${total}" minFractionDigits="2"/></span>
</div>
</div>
<div class="submitOrderDiv">
<button type="submit" class="submitOrderButton">提交订单</button>
</div>
</form>
</div>
HOW2J公众号,关注后实时获知最新的教程和优惠活动,谢谢。
问答区域
2021-07-30
站长 为什么启动tomcat的时候 报异常:com.how2java.tmall.pojo.OrderItem类 没有序列化???
回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
2021-03-25
站长:buyPage.jsp里的表单信息是不是没有传递过去啊
2021-03-20
你好,站长大人。在https://how2j.cn/tmall/foreproduct?pid=91#nowhere页面运行逻辑有个问题,就是用户购买下单并支付成功后,对应产品的库存数没有减少。
2020-05-01
点击立即购买,会报空指针异常
2020-04-26
站长大大,有没有办法,让这个项目的支付用支付宝沙箱实现啊 太难了
提问太多,页面渲染太慢,为了加快渲染速度,本页最多只显示几条提问。还有 11 条以前的提问,请 点击查看
提问之前请登陆
提问已经提交成功,正在审核。 请于 我的提问 处查看提问记录,谢谢
|