首页>代码>S2SH框架开发的简单demo实例>/SSH_Order/src/com/bwie/action/OrderAction.java
package com.bwie.action;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.bwie.dto.Goods;
import com.bwie.dto.Order;
import com.bwie.service.OrderService;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
@Controller
public class OrderAction extends ActionSupport{

	@Autowired
	private OrderService service;
	private List<?> orderList;
	private Order order;
	private String gid;
	
	public String list(){
		orderList = service.list();
		return "list";
	}
	
	public String deleteOrder() {
		service.deleteOrder(order);
		return SUCCESS;
	}
	
	public String toUpdate() {
		return "update";
	}
	
	public void getData() throws Exception {
		Map<String, Object> map = service.getData(order);
		String json = JSON.toJSONString(map, SerializerFeature.DisableCircularReferenceDetect);
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setCharacterEncoding("UTF-8");
		response.getWriter().print(json);
	}
	
	public void updateOrder() {
		Set<Goods> goods = new HashSet<Goods>();
		String[] gids = gid.split(", ");
		for (String s : gids) {
			goods.add(new Goods(Integer.parseInt(s)));
		}
		order.setGoods(goods);
		service.updateOrder(order);
	}
	
	public String toAdd() {
		return "add";
	}
	
	public void getGoodsList() throws Exception {
		List<?> list = service.getGoodsList();
		String json = JSON.toJSONString(list, SerializerFeature.DisableCircularReferenceDetect);
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setCharacterEncoding("UTF-8");
		response.getWriter().print(json);
	}
	
	public void addOrder() {
		Set<Goods> goods = new HashSet<Goods>();
		String[] gids = gid.split(", ");
		for (String s : gids) {
			goods.add(new Goods(Integer.parseInt(s)));
		}
		order.setGoods(goods);
		service.addOrder(order);
	}
	
	public String payOrder() {
		/**
		 * 1、现将要修改的订单信息查询,在进行修改支付状态
		 */
		/*Order o = service.getOrderByOid(order);
		o.setStatus(1);
		service.updateOrder(o);*/
		/**
		 * 2、实现自定义修改
		 */
		service.updateStatus(order);
		return SUCCESS;
	}
	
	public String deleteMoreOrder() {
		List<Order> list = new ArrayList<Order>();
		String oids = "1, 2";
		String[] ss = oids.split(", ");
		for (String s : ss) {
			list.add(new Order(Integer.parseInt(s)));
		}
		service.deleteMoreOrder(list);
		return SUCCESS;
	}

	/**
	 * +++++++++++++++++++++++++++++++++++++++++++++++
	 */
	public List<?> getOrderList() {
		return orderList;
	}

	public void setOrderList(List<?> orderList) {
		this.orderList = orderList;
	}

	public Order getOrder() {
		return order;
	}

	public void setOrder(Order order) {
		this.order = order;
	}

	public String getGid() {
		return gid;
	}

	public void setGid(String gid) {
		this.gid = gid;
	}
}
最近下载更多
mrmrmr2333  LV4 2020年11月6日
lianghui  LV13 2019年6月2日
aa991215  LV17 2019年6月1日
xiaoyu1200231  LV13 2019年5月26日
1206207437  LV8 2019年4月25日
13188866605  LV12 2018年11月4日
alexie  LV11 2018年3月27日
wlzyf冰冰  LV13 2017年12月11日
天下第一  LV12 2017年10月13日
alwen2770  LV4 2017年9月28日
最近浏览更多
xinnnnn  LV1 2月28日
张三的MySQL 2023年5月5日
暂无贡献等级
yut1an  LV2 2022年10月31日
xudong_y  LV4 2022年10月28日
dukie123  LV1 2022年2月13日
and123456  LV11 2022年2月11日
过过成功尺寸  LV7 2021年12月20日
lihuazhen  LV2 2021年12月17日
yexiansheng  LV1 2021年11月6日
北冥有猫  LV2 2021年6月14日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友