📄 shopcartaction.java
字号:
package com.royee.ecport.web.actions;
import com.royee.ecport.biz.*;
import com.royee.ecport.pojo.*;
import com.royee.ecport.web.UserAware;
public class ShopcartAction extends ActionBase implements UserAware {
/**
*
*/
private static final long serialVersionUID = 1L;
public static final String SESSION_KEY = "SHOPCART";
private static ProductBiz productBiz = (ProductBiz) BizFactory.getBiz("Product");
private static OrderBiz orderBiz = (OrderBiz) BizFactory.getBiz("Order");
private static StatusBiz statusBiz = (StatusBiz) BizFactory.getBiz("Status");
private static PaywayBiz paywayBiz = (PaywayBiz) BizFactory.getBiz("Payway");
private static OrderStatus status=statusBiz.getDefaultStatus();
private User user;
public void setUser(User u) {
user = u;
}
private long pid;
private long pwid;
private int num;
public void setPid(long pid) {
this.pid = pid;
}
public void setPwid(long pwid) {
this.pwid = pwid;
}
public void setNum(int num) {
this.num = num;
}
private Shopcart shopcart() {
if (session().getAttribute(SESSION_KEY) == null){
Shopcart shopcart=new Shopcart();
shopcart.setUser(user);
shopcart.setStatus(status);
session().setAttribute(SESSION_KEY, shopcart);
}
return (Shopcart) session().getAttribute(SESSION_KEY);
}
/**
* 加入购物车 pid 物品序号
*
* @return
*/
public String add() {
Shopcart shopcart = shopcart();
Product product = productBiz.getById(pid);
shopcart.add(product);
return SUCCESS;
}
/**
* 显示购物车
*/
@Override
public String execute() {
//首次运行初始化
shopcart();
return SHOPCART;
}
/**
* 删除订单项 id 购物车中临时订单id
*
* @return
*/
public String del() {
shopcart().remove(pid);
return SHOPCART;
}
/**
* 修改订单项 id 购物车中临时订单id num 商品数量
*
* @return
*/
public String save() {
shopcart().edit(pid, num);
return SHOPCART;
}
/**
* 提交订单
*
* @return
*/
public String submit() {
if(shopcart().getOrderLines().size()==0)
return INDEX;
Order order=shopcart().toOrder();
order.setPayway(paywayBiz.getById(pwid));
orderBiz.save(order);
shopcart().clear();
return INDEX;
}
/**
* 确认订单
*/
public String confirm(){
request().setAttribute("payway", paywayBiz.findAll());
return SUCCESS;
}
/**
* 清空购物车
*
* @return
*/
public String clear() {
shopcart().clear();
return SHOPCART;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -