package com.softeem.jingdong.action; import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Random; import javax.servlet.http.HttpSession; import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionSupport; import com.softeem.jingdong.entity.OrderBean; import com.softeem.jingdong.entity.UsersBean; import com.softeem.jingdong.service.OrderService; /** * 订单 Action * @author Administrator */ public class OrderAction extends ActionSupport { private static final long serialVersionUID = 8189598361091118151L; private OrderService orderService; private String name; private String address; private String phone; private String email; private String payWay; private OrderBean order = new OrderBean(); /** * 添加订单 */ public String addOrder(){ //添加订单号 order.setNo(this.getID()); order.setConsignee(name); order.setAddress(address); order.setPhone(phone); order.setEmail(email); order.setPayWay(payWay); order.setTime( new Timestamp( new Date().getTime() )); HttpSession session = ServletActionContext.getRequest().getSession(true); //调用 下订单方法 orderService.addOrder(order, (UsersBean)session.getAttribute("users")); //跳转到成功页面 return SUCCESS; } /** * 获取订单编号 13位 * yyyyMMdd + 5位随机数 */ public long getID(){ //yyyyMMdd SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); String t = sdf.format(new Date()); //5位随机数 Random r = new Random(); int m = 0; while( (m=r.nextInt(100000)) > 10000){ break; } //拼接 返回 随机 订单号 return Long.parseLong(t + m); } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getAddress() { return address; } public void setAddress(String address) { this.address = address; } public String getPhone() { return phone; } public void setPhone(String phone) { this.phone = phone; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getPayWay() { return payWay; } public void setPayWay(String payWay) { this.payWay = payWay; } public OrderBean getOrder() { return order; } public void setOrder(OrderBean order) { this.order = order; } public void setOrderService(OrderService orderService) { this.orderService = orderService; } }

baoligeer LV5
2022年6月6日
任星浩 LV1
2021年11月18日
giantinheart LV3
2021年5月23日
wusiyin LV14
2020年12月17日
曾学成 LV2
2020年12月14日
refreshbird LV1
2020年12月14日
方立亮 LV1
2020年11月6日
渺无人烟 LV11
2020年7月31日
cpemy_abc LV10
2020年6月9日
远大帅比 LV6
2020年5月19日

123456smt
6月10日
暂无贡献等级
sn764889012
4月16日
暂无贡献等级
dongandmin LV9
2024年12月31日
mianju
2024年12月19日
暂无贡献等级
lqzixi LV4
2024年11月6日
lyh1989 LV34
2024年7月21日
lyt010628 LV4
2024年7月9日
曾显示 LV6
2024年7月7日
樱花味小然子 LV5
2024年7月2日
微信网友_7034303418945536 LV1
2024年6月12日