步骤 2 : 模仿和排错 步骤 3 : 购物车页面操作 步骤 4 : 调整订单数量 步骤 5 : 删除订单项 步骤 6 : 提交到结算页面
增值内容,请先登录
完整的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项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
var page = "forechangeOrderItem";
$.post(
page,
{"product.id":pid,"num":num},
function(result){
if("success"!=result){
location.href="login.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";
}
package com.how2java.tmall.action;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
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.ProductImageService;
import com.opensymphony.xwork2.ActionContext;
public class ForeAction extends Action4Result {
@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项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
if(deleteOrderItem){
var page="foredeleteOrderItem";
$.post(
page,
{"orderItem.id":deleteOrderItemid},
function(result){
if("success"==result){
$("tr.cartProductItemTR[oiid="+deleteOrderItemid+"]").hide();
}
else{
location.href="login.jsp";
}
}
);
}
@Action("foredeleteOrderItem")
public String deleteOrderItem(){
orderItemService.delete(orderItem);
return "success.jsp";
}
package com.how2java.tmall.action;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
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.ProductImageService;
import com.opensymphony.xwork2.ActionContext;
public class ForeAction extends Action4Result {
@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项目经验,为简历加上一个有吸引力的砝码.
增值内容,点击购买
使用爬虫已经被系统记录,请勿使用爬虫,增大封号风险。 如果是误封 ,请联系站长,谢谢
HOW2J公众号,关注后实时获知最新的教程和优惠活动,谢谢。
问答区域
2019-03-25
请站长大人帮忙看看这里是不是写错了
回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
2017-11-06
关于同步调整订单数量的代码实现方法的疑惑
回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
2017-09-14
请问为什么后面这几个功能开始就不需要持久化了再操作数据库
2017-09-14
关于这一段JQ代码的疑问
提问之前请登陆
提问已经提交成功,正在审核。 请于 我的提问 处查看提问记录,谢谢
|