1 package com.zq.www.mis.action; 2 3 import java.util.List; 4 5 import org.apache.struts2.convention.annotation.Result; 6 import org.apache.struts2.convention.annotation.Results; 7 import org.springframework.beans.factory.annotation.Autowired; 8 9 import com.zq.www.common.BaseAction; 10 import com.zq.www.mis.dao.TorderManagerDAO; 11 /** 12 * 13 * @author zzw 订单审核 14 * 15 */ 16 @SuppressWarnings("serial") 17 @Results( { 18 @Result(name = "show", location = "/BacksAdmin/order_approve/list.jsp"), 19 @Result(name = "shenhes", location = "/BacksAdmin/order_approve/list.jsp") 20 21 }) 22 public class Order1Action extends BaseAction{ 23 @Autowired 24 private TorderManagerDAO dao; 25 List<String[]> orderlist; 26 private Integer id; 27 private String ajaxtext; 28 29 30 31 32 33 34 35 36 37 38 39 //前台展示全部待审核的信息 40 public String show1() throws Exception{ 41 orderlist=dao.select(); 42 this.ajaxSendJson(orderlist, true); //我封装了代码 43 return null; 44 } 45 //这个函数将对应参数的的支付状态修改为"已退款" 46 public String shenhe() throws Exception{ 47 System.out.println("id="+id); 48 dao.updateStatus(id); 49 this.ajaxSendSuccess(); 50 return null; 51 } 52 //批量修改 53 public String shenhes() throws Exception 54 { 55 System.out.println("ajaxtext="+ajaxtext); 56 String[] a=ajaxtext.split(","); 57 for(int i=1;i<a.length;i++) 58 { 59 System.out.println("拆开的值是;"+a[i]); 60 dao.updateStatus(Integer.parseInt(a[i])); 61 62 } 63 return "shenhes"; 64 } 65 66 67 68 69 70 71 72 73 74 75 76 77 78 public List<String[]> getOrderlist() { 79 return orderlist; 80 } 81 public void setOrderlist(List<String[]> orderlist) { 82 this.orderlist = orderlist; 83 } 84 public Integer getId() { 85 return id; 86 } 87 public void setId(Integer id) { 88 this.id = id; 89 } 90 public String getAjaxtext() { 91 return ajaxtext; 92 } 93 public void setAjaxtext(String ajaxtext) { 94 this.ajaxtext = ajaxtext; 95 } 96 97 }
我封装的代码如下
1 package com.zq.www.common; 2 3 import javax.servlet.ServletContext; 4 import javax.servlet.http.HttpServletRequest; 5 import javax.servlet.http.HttpServletResponse; 6 import javax.servlet.http.HttpSession; 7 8 import org.apache.struts2.ServletActionContext; 9 10 import com.alibaba.fastjson.JSON; 11 import com.alibaba.fastjson.serializer.SerializerFeature; 12 import com.opensymphony.xwork2.ActionSupport; 13 14 15 //提取的公共Action 16 public class BaseAction extends ActionSupport{ 17 18 19 // 取得Request/Response/Session的简化函数 // 20 21 /** 22 * 取得HttpRequest的简化方法. 23 */ 24 public static HttpServletRequest getRequest() { 25 return ServletActionContext.getRequest(); 26 } 27 28 /** 29 * 取得HttpResponse的简化方法. 30 */ 31 public static HttpServletResponse getResponse() { 32 return ServletActionContext.getResponse(); 33 } 34 35 /** 36 * 取得HttpSession的简化方法. 37 */ 38 public static HttpSession getSession() { 39 return ServletActionContext.getRequest().getSession(); 40 } 41 42 /** 43 * 取得Application的简化方法. 44 */ 45 public static ServletContext getApplication() { 46 return ServletActionContext.getServletContext(); 47 } 48 49 50 /** 51 * 发送普通的json 52 */ 53 public static void ajaxSendJson(Object obj) throws Exception{ 54 ajaxSendJson(obj,false); 55 } 56 57 /** 58 * 发送普通的json,带日期 59 */ 60 public static void ajaxSendJson(Object obj,boolean isDate) throws Exception{ 61 String result=""; 62 if(isDate) 63 result=JSON.toJSONString(obj,SerializerFeature.WriteDateUseDateFormat); 64 else 65 result=JSON.toJSONString(obj); 66 getResponse().getWriter().write(result); 67 } 68 69 /* 70 *发送success 71 * 72 */ 73 public static void ajaxSendSuccess()throws Exception{ 74 getResponse().getWriter().write(JSON.toJSONString("success")); 75 } 76 77 78 79 80 }
时间: 2024-10-14 01:59:29