how2j.cn

下载区
文件名 文件大小
请先登录 18m
增值内容 18m
18m
使用站长秘制下载工具
步骤 1 : 先运行,看到效果,再学习   
步骤 2 : 模仿和排错   
步骤 3 : 结算页操作   
步骤 4 : 运行效果   
步骤 5 : OrderService   
步骤 6 : OrderServiceImpl   
步骤 7 : 对createOrder进行事务管理   
步骤 8 : ForeAction.createOrder   
步骤 9 : 确认支付页   
步骤 10 : 支付成功页   

步骤 1 :

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

edit
增值内容,请先登录
完整的SSH模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSH一整套技术栈, 从无到有涵盖全部133个知识点,571个开发步骤, 充实SSH项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
增值内容,请先登录
完整的SSH模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSH一整套技术栈, 从无到有涵盖全部133个知识点,571个开发步骤, 充实SSH项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
增值内容,请先登录
完整的SSH模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSH一整套技术栈, 从无到有涵盖全部133个知识点,571个开发步骤, 充实SSH项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
结算页操作
增值内容,请先登录
完整的SSH模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSH一整套技术栈, 从无到有涵盖全部133个知识点,571个开发步骤, 充实SSH项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
运行效果
增值内容,请先登录
完整的SSH模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSH一整套技术栈, 从无到有涵盖全部133个知识点,571个开发步骤, 充实SSH项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package com.how2java.tmall.service; import java.util.List; import com.how2java.tmall.pojo.Order; import com.how2java.tmall.pojo.OrderItem; public interface OrderService extends BaseService { public static final String waitPay = "waitPay"; public static final String waitDelivery = "waitDelivery"; public static final String waitConfirm = "waitConfirm"; public static final String waitReview = "waitReview"; public static final String finish = "finish"; public static final String delete = "delete"; public float createOrder(Order order, List<OrderItem> ois); }
package com.how2java.tmall.service;

import java.util.List;

import com.how2java.tmall.pojo.Order;
import com.how2java.tmall.pojo.OrderItem;

public interface OrderService extends BaseService {
	public static final String waitPay = "waitPay";
	public static final String waitDelivery = "waitDelivery";
	public static final String waitConfirm = "waitConfirm";
	public static final String waitReview = "waitReview";
	public static final String finish = "finish";
	public static final String delete = "delete";	
	
	public float createOrder(Order order, List<OrderItem> ois);
}
增值内容,请先登录
完整的SSH模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSH一整套技术栈, 从无到有涵盖全部133个知识点,571个开发步骤, 充实SSH项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
package com.how2java.tmall.service.impl; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; import com.how2java.tmall.pojo.Order; import com.how2java.tmall.pojo.OrderItem; import com.how2java.tmall.service.OrderItemService; import com.how2java.tmall.service.OrderService; @Service public class OrderServiceImpl extends BaseServiceImpl implements OrderService { @Autowired OrderItemService orderItemService; @Transactional(propagation=Propagation.REQUIRED,rollbackForClassName="Exception") public float createOrder(Order order, List<OrderItem> ois) { save(order); float total =0; for (OrderItem oi: ois) { oi.setOrder(order); orderItemService.update(oi); total+=oi.getProduct().getPromotePrice()*oi.getNumber(); } return total; } }
步骤 7 :

对createOrder进行事务管理

edit
增值内容,请先登录
完整的SSH模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSH一整套技术栈, 从无到有涵盖全部133个知识点,571个开发步骤, 充实SSH项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
@Transactional(propagation=Propagation.REQUIRED,rollbackForClassName="Exception") public float createOrder(Order order, List<OrderItem> ois) { save(order); float total =0; for (OrderItem oi: ois) { oi.setOrder(order); orderItemService.update(oi); total+=oi.getProduct().getPromotePrice()*oi.getNumber(); } return total; }
@Transactional(propagation=Propagation.REQUIRED,rollbackForClassName="Exception")
	public float createOrder(Order order, List<OrderItem> ois) {
		save(order);
		float total =0;
		for (OrderItem oi: ois) {
	        oi.setOrder(order);
	        orderItemService.update(oi);
	        total+=oi.getProduct().getPromotePrice()*oi.getNumber();
	    }
		return total;
	}
步骤 8 :

ForeAction.createOrder

edit
增值内容,请先登录
完整的SSH模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSH一整套技术栈, 从无到有涵盖全部133个知识点,571个开发步骤, 充实SSH项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
@Action("forecreateOrder") public String createOrder(){ List<OrderItem> ois= (List<OrderItem>) ActionContext.getContext().getSession().get("orderItems"); if(ois.isEmpty()) return "login.jsp"; User user =(User) ActionContext.getContext().getSession().get("user"); String orderCode = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()) +RandomUtils.nextInt(10000); order.setOrderCode(orderCode); order.setCreateDate(new Date()); order.setUser(user); order.setStatus(OrderService.waitPay); total = orderService.createOrder(order, ois); return "alipayPage"; }
package com.how2java.tmall.action; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.List; import org.apache.commons.lang.xwork.math.RandomUtils; import org.apache.struts2.convention.annotation.Action; import org.springframework.web.util.HtmlUtils; import com.how2java.tmall.comparator.ProductAllComparator; import com.how2java.tmall.comparator.ProductDateComparator; import com.how2java.tmall.comparator.ProductPriceComparator; import com.how2java.tmall.comparator.ProductReviewComparator; import com.how2java.tmall.comparator.ProductSaleCountComparator; import com.how2java.tmall.pojo.OrderItem; import com.how2java.tmall.pojo.Product; import com.how2java.tmall.pojo.User; import com.how2java.tmall.service.OrderService; import com.how2java.tmall.service.ProductImageService; import com.opensymphony.xwork2.ActionContext; public class ForeAction extends Action4Result { @Action("forecreateOrder") public String createOrder(){ List<OrderItem> ois= (List<OrderItem>) ActionContext.getContext().getSession().get("orderItems"); if(ois.isEmpty()) return "login.jsp"; User user =(User) ActionContext.getContext().getSession().get("user"); String orderCode = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()) +RandomUtils.nextInt(10000); order.setOrderCode(orderCode); order.setCreateDate(new Date()); order.setUser(user); order.setStatus(OrderService.waitPay); total = orderService.createOrder(order, ois); return "alipayPage"; } @Action("foredeleteOrderItem") public String deleteOrderItem(){ orderItemService.delete(orderItem); return "success.jsp"; } @Action("forechangeOrderItem") public String changeOrderItem() { User user =(User) ActionContext.getContext().getSession().get("user"); List<OrderItem> ois = orderItemService.list("user",user,"order", null); for (OrderItem oi : ois) { if(oi.getProduct().getId()==product.getId()){ oi.setNumber(num); orderItemService.update(oi); break; } } return "success.jsp"; } @Action("forecart") public String cart() { User user =(User) ActionContext.getContext().getSession().get("user"); orderItems = orderItemService.list("user",user,"order", null); for (OrderItem orderItem : orderItems) productImageService.setFirstProdutImage(orderItem.getProduct()); return "cart.jsp"; } @Action("foreaddCart") public String addCart() { User user =(User) ActionContext.getContext().getSession().get("user"); boolean found = false; List<OrderItem> ois = orderItemService.list("user",user,"order", null); for (OrderItem oi : ois) { if(oi.getProduct().getId()==product.getId()){ oi.setNumber(oi.getNumber()+num); orderItemService.update(oi); found = true; break; } } if(!found){ OrderItem oi = new OrderItem(); oi.setUser(user); oi.setNumber(num); oi.setProduct(product); orderItemService.save(oi); } return "success.jsp"; } @Action("forebuy") public String buy() { orderItems = new ArrayList<>(); for (int oiid : oiids) { OrderItem oi= (OrderItem) orderItemService.get(oiid); total +=oi.getProduct().getPromotePrice()*oi.getNumber(); orderItems.add(oi); productImageService.setFirstProdutImage(oi.getProduct()); } ActionContext.getContext().getSession().put("orderItems", orderItems); return "buy.jsp"; } @Action("forebuyone") public String buyone() { User user =(User) ActionContext.getContext().getSession().get("user"); boolean found = false; List<OrderItem> ois = orderItemService.list("user",user,"order", null); for (OrderItem oi : ois) { if(oi.getProduct().getId()==product.getId()){ oi.setNumber(oi.getNumber()+num); orderItemService.update(oi); found = true; oiid = oi.getId(); break; } } if(!found){ OrderItem oi = new OrderItem(); oi.setUser(user); oi.setNumber(num); oi.setProduct(product); orderItemService.save(oi); oiid = oi.getId(); } return "buyPage"; } @Action("foresearch") public String search(){ products= productService.search(keyword,0,20); productService.setSaleAndReviewNumber(products); for (Product product : products) productImageService.setFirstProdutImage(product); return "searchResult.jsp"; } @Action("forecategory") public String category(){ t2p(category); productService.fill(category); productService.setSaleAndReviewNumber(category.getProducts()); if(null!=sort){ switch(sort){ case "review": Collections.sort(category.getProducts(),new ProductReviewComparator()); break; case "date" : Collections.sort(category.getProducts(),new ProductDateComparator()); break; case "saleCount" : Collections.sort(category.getProducts(),new ProductSaleCountComparator()); break; case "price": Collections.sort(category.getProducts(),new ProductPriceComparator()); break; case "all": Collections.sort(category.getProducts(),new ProductAllComparator()); break; } } return "category.jsp"; } @Action("foreloginAjax") public String loginAjax() { user.setName(HtmlUtils.htmlEscape(user.getName())); User user_session = userService.get(user.getName(),user.getPassword()); if(null==user_session) return "fail.jsp"; ActionContext.getContext().getSession().put("user", user_session); return "success.jsp"; } @Action("forecheckLogin") public String checkLogin() { User u =(User) ActionContext.getContext().getSession().get("user"); if(null==u) return "fail.jsp"; else return "success.jsp"; } @Action("foreproduct") public String product() { t2p(product); productImageService.setFirstProdutImage(product); productSingleImages = productImageService.list("product",product,"type", ProductImageService.type_single); productDetailImages = productImageService.list("product",product,"type", ProductImageService.type_detail); product.setProductSingleImages(productSingleImages); product.setProductDetailImages(productDetailImages); propertyValues = propertyValueService.listByParent(product); reviews = reviewService.listByParent(product); productService.setSaleAndReviewNumber(product); return "product.jsp"; } @Action("forelogout") public String logout() { ActionContext.getContext().getSession().remove("user"); return "homePage"; } @Action("forelogin") public String login() { user.setName(HtmlUtils.htmlEscape(user.getName())); User user_session = userService.get(user.getName(),user.getPassword()); if(null==user_session){ msg= "账号密码错误"; return "login.jsp"; } ActionContext.getContext().getSession().put("user", user_session); return "homePage"; } @Action("foreregister") public String register() { user.setName(HtmlUtils.htmlEscape(user.getName())); boolean exist = userService.isExist(user.getName()); if(exist){ msg = "用户名已经被使用,不能使用"; return "register.jsp"; } userService.save(user); return "registerSuccessPage"; } @Action("forehome") public String home() { categorys = categoryService.list(); productService.fill(categorys); productService.fillByRow(categorys); return "home.jsp"; } }
增值内容,请先登录
完整的SSH模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSH一整套技术栈, 从无到有涵盖全部133个知识点,571个开发步骤, 充实SSH项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
确认支付页
public String alipay(HttpActionRequest request, HttpActionResponse response, Page page){ return "alipay.jsp"; }
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%> <%@include file="include/header.jsp"%> <%@include file="include/top.jsp"%> <%@include file="include/cart/alipayPage.jsp"%> <%@include file="include/footer.jsp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%> <div class="aliPayPageDiv"> <div class="aliPayPageLogo"> <img class="pull-left" src="img/site/simpleLogo.png"> <div style="clear:both"></div> </div> <div> <span class="confirmMoneyText">扫一扫付款(元)</span> <span class="confirmMoney"> ¥<fmt:formatNumber type="number" value="${param.total}" minFractionDigits="2"/></span> </div> <div> <img class="aliPayImg" src="img/site/alipay2wei.png"> </div> <div> <a href="forepayed?order.id=${order.id}&total=${param.total}"><button class="confirmPay">确认支付</button></a> </div> </div>
package com.how2java.tmall.action; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.List; import org.apache.commons.lang.xwork.math.RandomUtils; import org.apache.struts2.convention.annotation.Action; import org.springframework.web.util.HtmlUtils; import com.how2java.tmall.comparator.ProductAllComparator; import com.how2java.tmall.comparator.ProductDateComparator; import com.how2java.tmall.comparator.ProductPriceComparator; import com.how2java.tmall.comparator.ProductReviewComparator; import com.how2java.tmall.comparator.ProductSaleCountComparator; import com.how2java.tmall.pojo.OrderItem; import com.how2java.tmall.pojo.Product; import com.how2java.tmall.pojo.User; import com.how2java.tmall.service.OrderService; import com.how2java.tmall.service.ProductImageService; import com.opensymphony.xwork2.ActionContext; public class ForeAction extends Action4Result { @Action("forealipay") public String forealipay(){ return "alipay.jsp"; } @Action("forecreateOrder") public String createOrder(){ List<OrderItem> ois= (List<OrderItem>) ActionContext.getContext().getSession().get("orderItems"); if(ois.isEmpty()) return "login.jsp"; User user =(User) ActionContext.getContext().getSession().get("user"); String orderCode = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()) +RandomUtils.nextInt(10000); order.setOrderCode(orderCode); order.setCreateDate(new Date()); order.setUser(user); order.setStatus(OrderService.waitPay); total = orderService.createOrder(order, ois); return "alipayPage"; } @Action("foredeleteOrderItem") public String deleteOrderItem(){ orderItemService.delete(orderItem); return "success.jsp"; } @Action("forechangeOrderItem") public String changeOrderItem() { User user =(User) ActionContext.getContext().getSession().get("user"); List<OrderItem> ois = orderItemService.list("user",user,"order", null); for (OrderItem oi : ois) { if(oi.getProduct().getId()==product.getId()){ oi.setNumber(num); orderItemService.update(oi); break; } } return "success.jsp"; } @Action("forecart") public String cart() { User user =(User) ActionContext.getContext().getSession().get("user"); orderItems = orderItemService.list("user",user,"order", null); for (OrderItem orderItem : orderItems) productImageService.setFirstProdutImage(orderItem.getProduct()); return "cart.jsp"; } @Action("foreaddCart") public String addCart() { User user =(User) ActionContext.getContext().getSession().get("user"); boolean found = false; List<OrderItem> ois = orderItemService.list("user",user,"order", null); for (OrderItem oi : ois) { if(oi.getProduct().getId()==product.getId()){ oi.setNumber(oi.getNumber()+num); orderItemService.update(oi); found = true; break; } } if(!found){ OrderItem oi = new OrderItem(); oi.setUser(user); oi.setNumber(num); oi.setProduct(product); orderItemService.save(oi); } return "success.jsp"; } @Action("forebuy") public String buy() { orderItems = new ArrayList<>(); for (int oiid : oiids) { OrderItem oi= (OrderItem) orderItemService.get(oiid); total +=oi.getProduct().getPromotePrice()*oi.getNumber(); orderItems.add(oi); productImageService.setFirstProdutImage(oi.getProduct()); } ActionContext.getContext().getSession().put("orderItems", orderItems); return "buy.jsp"; } @Action("forebuyone") public String buyone() { User user =(User) ActionContext.getContext().getSession().get("user"); boolean found = false; List<OrderItem> ois = orderItemService.list("user",user,"order", null); for (OrderItem oi : ois) { if(oi.getProduct().getId()==product.getId()){ oi.setNumber(oi.getNumber()+num); orderItemService.update(oi); found = true; oiid = oi.getId(); break; } } if(!found){ OrderItem oi = new OrderItem(); oi.setUser(user); oi.setNumber(num); oi.setProduct(product); orderItemService.save(oi); oiid = oi.getId(); } return "buyPage"; } @Action("foresearch") public String search(){ products= productService.search(keyword,0,20); productService.setSaleAndReviewNumber(products); for (Product product : products) productImageService.setFirstProdutImage(product); return "searchResult.jsp"; } @Action("forecategory") public String category(){ t2p(category); productService.fill(category); productService.setSaleAndReviewNumber(category.getProducts()); if(null!=sort){ switch(sort){ case "review": Collections.sort(category.getProducts(),new ProductReviewComparator()); break; case "date" : Collections.sort(category.getProducts(),new ProductDateComparator()); break; case "saleCount" : Collections.sort(category.getProducts(),new ProductSaleCountComparator()); break; case "price": Collections.sort(category.getProducts(),new ProductPriceComparator()); break; case "all": Collections.sort(category.getProducts(),new ProductAllComparator()); break; } } return "category.jsp"; } @Action("foreloginAjax") public String loginAjax() { user.setName(HtmlUtils.htmlEscape(user.getName())); User user_session = userService.get(user.getName(),user.getPassword()); if(null==user_session) return "fail.jsp"; ActionContext.getContext().getSession().put("user", user_session); return "success.jsp"; } @Action("forecheckLogin") public String checkLogin() { User u =(User) ActionContext.getContext().getSession().get("user"); if(null==u) return "fail.jsp"; else return "success.jsp"; } @Action("foreproduct") public String product() { t2p(product); productImageService.setFirstProdutImage(product); productSingleImages = productImageService.list("product",product,"type", ProductImageService.type_single); productDetailImages = productImageService.list("product",product,"type", ProductImageService.type_detail); product.setProductSingleImages(productSingleImages); product.setProductDetailImages(productDetailImages); propertyValues = propertyValueService.listByParent(product); reviews = reviewService.listByParent(product); productService.setSaleAndReviewNumber(product); return "product.jsp"; } @Action("forelogout") public String logout() { ActionContext.getContext().getSession().remove("user"); return "homePage"; } @Action("forelogin") public String login() { user.setName(HtmlUtils.htmlEscape(user.getName())); User user_session = userService.get(user.getName(),user.getPassword()); if(null==user_session){ msg= "账号密码错误"; return "login.jsp"; } ActionContext.getContext().getSession().put("user", user_session); return "homePage"; } @Action("foreregister") public String register() { user.setName(HtmlUtils.htmlEscape(user.getName())); boolean exist = userService.isExist(user.getName()); if(exist){ msg = "用户名已经被使用,不能使用"; return "register.jsp"; } userService.save(user); return "registerSuccessPage"; } @Action("forehome") public String home() { categorys = categoryService.list(); productService.fill(categorys); productService.fillByRow(categorys); return "home.jsp"; } }
增值内容,请先登录
完整的SSH模仿天猫项目,使用J2SE、前端技术(包含所有前端jsp文件)、J2EE,SSH一整套技术栈, 从无到有涵盖全部133个知识点,571个开发步骤, 充实SSH项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
支付成功页
@Action("forepayed") public String payed() { t2p(order); order.setStatus(OrderService.waitDelivery); order.setPayDate(new Date()); orderService.update(order); return "payed.jsp"; }
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%> <%@include file="include/header.jsp"%> <%@include file="include/top.jsp"%> <%@include file="include/simpleSearch.jsp"%> <%@include file="include/cart/payedPage.jsp"%> <%@include file="include/footer.jsp"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" isELIgnored="false"%> <div class="payedDiv"> <div class="payedTextDiv"> <img src="img/site/paySuccess.png"> <span>您已成功付款</span> </div> <div class="payedAddressInfo"> <ul> <li>收货地址:${order.address} ${order.receiver} ${order.mobile }</li> <li>实付款:<span class="payedInfoPrice"> ¥<fmt:formatNumber type="number" value="${param.total}" minFractionDigits="2"/> </li> <li>预计08月08日送达 </li> </ul> <div class="paedCheckLinkDiv"> 您可以 <a class="payedCheckLink" href="forebought">查看已买到的宝贝</a> <a class="payedCheckLink" href="forebought">查看交易详情 </a> </div> </div> <div class="payedSeperateLine"> </div> <div class="warningDiv"> <img src="img/site/warning.png"> <b>安全提醒:</b>下单后,<span class="redColor boldWord">用QQ给您发送链接办理退款的都是骗子!</span>天猫不存在系统升级,订单异常等问题,谨防假冒客服电话诈骗! </div> </div>
package com.how2java.tmall.action; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.List; import org.apache.commons.lang.xwork.math.RandomUtils; import org.apache.struts2.convention.annotation.Action; import org.springframework.web.util.HtmlUtils; import com.how2java.tmall.comparator.ProductAllComparator; import com.how2java.tmall.comparator.ProductDateComparator; import com.how2java.tmall.comparator.ProductPriceComparator; import com.how2java.tmall.comparator.ProductReviewComparator; import com.how2java.tmall.comparator.ProductSaleCountComparator; import com.how2java.tmall.pojo.OrderItem; import com.how2java.tmall.pojo.Product; import com.how2java.tmall.pojo.User; import com.how2java.tmall.service.OrderService; import com.how2java.tmall.service.ProductImageService; import com.opensymphony.xwork2.ActionContext; public class ForeAction extends Action4Result { @Action("forepayed") public String payed() { t2p(order); order.setStatus(OrderService.waitDelivery); order.setPayDate(new Date()); orderService.update(order); return "payed.jsp"; } @Action("forealipay") public String forealipay(){ return "alipay.jsp"; } @Action("forecreateOrder") public String createOrder(){ List<OrderItem> ois= (List<OrderItem>) ActionContext.getContext().getSession().get("orderItems"); if(ois.isEmpty()) return "login.jsp"; User user =(User) ActionContext.getContext().getSession().get("user"); String orderCode = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date()) +RandomUtils.nextInt(10000); order.setOrderCode(orderCode); order.setCreateDate(new Date()); order.setUser(user); order.setStatus(OrderService.waitPay); total = orderService.createOrder(order, ois); return "alipayPage"; } @Action("foredeleteOrderItem") public String deleteOrderItem(){ orderItemService.delete(orderItem); return "success.jsp"; } @Action("forechangeOrderItem") public String changeOrderItem() { User user =(User) ActionContext.getContext().getSession().get("user"); List<OrderItem> ois = orderItemService.list("user",user,"order", null); for (OrderItem oi : ois) { if(oi.getProduct().getId()==product.getId()){ oi.setNumber(num); orderItemService.update(oi); break; } } return "success.jsp"; } @Action("forecart") public String cart() { User user =(User) ActionContext.getContext().getSession().get("user"); orderItems = orderItemService.list("user",user,"order", null); for (OrderItem orderItem : orderItems) productImageService.setFirstProdutImage(orderItem.getProduct()); return "cart.jsp"; } @Action("foreaddCart") public String addCart() { User user =(User) ActionContext.getContext().getSession().get("user"); boolean found = false; List<OrderItem> ois = orderItemService.list("user",user,"order", null); for (OrderItem oi : ois) { if(oi.getProduct().getId()==product.getId()){ oi.setNumber(oi.getNumber()+num); orderItemService.update(oi); found = true; break; } } if(!found){ OrderItem oi = new OrderItem(); oi.setUser(user); oi.setNumber(num); oi.setProduct(product); orderItemService.save(oi); } return "success.jsp"; } @Action("forebuy") public String buy() { orderItems = new ArrayList<>(); for (int oiid : oiids) { OrderItem oi= (OrderItem) orderItemService.get(oiid); total +=oi.getProduct().getPromotePrice()*oi.getNumber(); orderItems.add(oi); productImageService.setFirstProdutImage(oi.getProduct()); } ActionContext.getContext().getSession().put("orderItems", orderItems); return "buy.jsp"; } @Action("forebuyone") public String buyone() { User user =(User) ActionContext.getContext().getSession().get("user"); boolean found = false; List<OrderItem> ois = orderItemService.list("user",user,"order", null); for (OrderItem oi : ois) { if(oi.getProduct().getId()==product.getId()){ oi.setNumber(oi.getNumber()+num); orderItemService.update(oi); found = true; oiid = oi.getId(); break; } } if(!found){ OrderItem oi = new OrderItem(); oi.setUser(user); oi.setNumber(num); oi.setProduct(product); orderItemService.save(oi); oiid = oi.getId(); } return "buyPage"; } @Action("foresearch") public String search(){ products= productService.search(keyword,0,20); productService.setSaleAndReviewNumber(products); for (Product product : products) productImageService.setFirstProdutImage(product); return "searchResult.jsp"; } @Action("forecategory") public String category(){ t2p(category); productService.fill(category); productService.setSaleAndReviewNumber(category.getProducts()); if(null!=sort){ switch(sort){ case "review": Collections.sort(category.getProducts(),new ProductReviewComparator()); break; case "date" : Collections.sort(category.getProducts(),new ProductDateComparator()); break; case "saleCount" : Collections.sort(category.getProducts(),new ProductSaleCountComparator()); break; case "price": Collections.sort(category.getProducts(),new ProductPriceComparator()); break; case "all": Collections.sort(category.getProducts(),new ProductAllComparator()); break; } } return "category.jsp"; } @Action("foreloginAjax") public String loginAjax() { user.setName(HtmlUtils.htmlEscape(user.getName())); User user_session = userService.get(user.getName(),user.getPassword()); if(null==user_session) return "fail.jsp"; ActionContext.getContext().getSession().put("user", user_session); return "success.jsp"; } @Action("forecheckLogin") public String checkLogin() { User u =(User) ActionContext.getContext().getSession().get("user"); if(null==u) return "fail.jsp"; else return "success.jsp"; } @Action("foreproduct") public String product() { t2p(product); productImageService.setFirstProdutImage(product); productSingleImages = productImageService.list("product",product,"type", ProductImageService.type_single); productDetailImages = productImageService.list("product",product,"type", ProductImageService.type_detail); product.setProductSingleImages(productSingleImages); product.setProductDetailImages(productDetailImages); propertyValues = propertyValueService.listByParent(product); reviews = reviewService.listByParent(product); productService.setSaleAndReviewNumber(product); return "product.jsp"; } @Action("forelogout") public String logout() { ActionContext.getContext().getSession().remove("user"); return "homePage"; } @Action("forelogin") public String login() { user.setName(HtmlUtils.htmlEscape(user.getName())); User user_session = userService.get(user.getName(),user.getPassword()); if(null==user_session){ msg= "账号密码错误"; return "login.jsp"; } ActionContext.getContext().getSession().put("user", user_session); return "homePage"; } @Action("foreregister") public String register() { user.setName(HtmlUtils.htmlEscape(user.getName())); boolean exist = userService.isExist(user.getName()); if(exist){ msg = "用户名已经被使用,不能使用"; return "register.jsp"; } userService.save(user); return "registerSuccessPage"; } @Action("forehome") public String home() { categorys = categoryService.list(); productService.fill(categorys); productService.fillByRow(categorys); return "home.jsp"; } }


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


问答区域    
2020-07-09 请问为什么要单独做一个@Action("forealipay") 来跳转支付页
aasdasd

为什么不在@Action("forecreateOrder")之后直接跳到支付页




1 个答案

how2j
答案时间:2020-07-11
它返回的是 return "alipayPage"; 这不就是支付页吗?



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




2018-08-01 创建订单时报错
Anshay




在OrderServieImpl的createOrder方法这里,按照站长说的加了事务控制的代码后,运行时生成订单就会报错,报错信息如图。然后把这行代码 @Transactional(propagation = Propagation.REQUIRED, rollbackForClassName = "Exception") 去掉去掉之后,就不会报错。请问报错的原因是为什么,说找不到transactionManager 这个bean,可是其他用事务的地方,也没有报错。
加载中
@Transactional(propagation = Propagation.REQUIRED, rollbackForClassName = "Exception")
	public float createOrder(Order order, List<OrderItem> ois) {
		save(order);
		float total = 0;
		for (OrderItem oi : ois) {
			oi.setOrder(order);
			orderItemService.update(oi);
			total += oi.getProduct().getPromotePrice() * oi.getNumber();
		}
		return total;
	}

							


1 个答案

how2j
答案时间:2018-08-02
在配置文件里没有定义这个东东。 你这样,用diffmerge软件,进行文件夹比较。把你自己做的项目文件夹,和我的可运行项目文件夹进行比较 这个软件很牛逼的,可以知道文件夹里哪两个文件不对,而且很明显地标记出来 我这里就有下载和教程: http://how2j.cn/k/18/18-1583/1583.html



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









提问之前请登陆
提问已经提交成功,正在审核。 请于 我的提问 处查看提问记录,谢谢
关于 实践项目-天猫整站SSH-生成订单 的提问

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

上传截图