1 Packagecom.zq.www.mis.action;2 3 Importjava.util.List;4 5 ImportOrg.apache.struts2.convention.annotation.Result;6 ImportOrg.apache.struts2.convention.annotation.Results;7 Importorg.springframework.beans.factory.annotation.Autowired;8 9 Importcom.zq.www.common.BaseAction;Ten ImportCom.zq.www.mis.dao.TorderManagerDAO; One /** A * - * @authorZZW Order Review - * the */ -@SuppressWarnings ("Serial") - @Results ({ -@Result (name = "Show", location = "/backsadmin/order_approve/list.jsp"), +@Result (name = "Shenhes", location = "/backsadmin/order_approve/list.jsp") - + }) A Public classOrder1actionextendsbaseaction{ at @Autowired - PrivateTordermanagerdao DAO; -List<string[]>orderlist; - PrivateInteger ID; - PrivateString Ajaxtext; - in - to + - the * $ Panax Notoginseng - the //Front desk showing all information to be audited + PublicString Show1 ()throwsexception{ Aorderlist=Dao.select (); the This. Ajaxsendjson (OrderList,true); I encapsulated the Code + return NULL; - } $ //This function modifies the payment status of the corresponding parameter to "refunded" $ PublicString Shenhe ()throwsexception{ -System.out.println ("id=" +ID); - dao.updatestatus (ID); the This. ajaxsendsuccess (); - return NULL;Wuyi } the //Batch Modification - PublicString shenhes ()throwsException Wu { -System.out.println ("ajaxtext=" +ajaxtext); AboutString[] A=ajaxtext.split (","); $ for(inti=1;i<a.length;i++) - { -SYSTEM.OUT.PRINTLN ("disassembled value is;" +a[i]); - Dao.updatestatus (Integer.parseint (a[i)); A + } the return"Shenhes"; - } $ the the the the - in the the About the the the + PublicList<string[]>getorderlist () { - returnorderlist; the }Bayi Public voidSetorderlist (list<string[]>orderlist) { the This. orderlist =orderlist; the } - PublicInteger getId () { - returnID; the } the Public voidsetId (Integer id) { the This. ID =ID; the } - PublicString Getajaxtext () { the returnAjaxtext; the } the Public voidSetajaxtext (String ajaxtext) {94 This. Ajaxtext =Ajaxtext; the } the the}
The code I encapsulated is as follows
1 PackageCom.zq.www.common;2 3 ImportJavax.servlet.ServletContext;4 Importjavax.servlet.http.HttpServletRequest;5 ImportJavax.servlet.http.HttpServletResponse;6 Importjavax.servlet.http.HttpSession;7 8 ImportOrg.apache.struts2.ServletActionContext;9 Ten ImportCom.alibaba.fastjson.JSON; One Importcom.alibaba.fastjson.serializer.SerializerFeature; A ImportCom.opensymphony.xwork2.ActionSupport; - - the //extracted public Action - Public classBaseactionextendsactionsupport{ - - + //simplified functions for obtaining request/response/session// - + /** A * Simplified method of obtaining HttpRequest. at */ - Public Statichttpservletrequest getrequest () { - returnservletactioncontext.getrequest (); - } - - /** in * Simplified method of obtaining HttpResponse. - */ to Public StaticHttpServletResponse GetResponse () { + returnservletactioncontext.getresponse (); - } the * /** $ * Simplified method of obtaining httpsession.Panax Notoginseng */ - Public StaticHttpSession getsession () { the returnservletactioncontext.getrequest (). getsession (); + } A the /** + * Simplified method of obtaining application. - */ $ Public StaticServletContext getapplication () { $ returnServletactioncontext.getservletcontext (); - } - the - /**Wuyi * Send normal JSON the */ - Public Static voidAjaxsendjson (Object obj)throwsexception{ WuAjaxsendjson (obj,false); - } About $ /** - * Send normal JSON with date - */ - Public Static voidAjaxsendjson (Object obj,BooleanIsDate)throwsexception{ AString result= ""; + if(isDate) theresult=json.tojsonstring (Obj,serializerfeature.writedateusedateformat); - Else $result=json.tojsonstring (obj); the getResponse (). Getwriter (). write (result); the } the the /* - * Send Success in * the */ the Public Static voidAjaxsendsuccess ()throwsexception{ AboutGetResponse (). Getwriter (). Write (Json.tojsonstring ("Success")); the } the the + - the}
How to write the code before and after the Ajax way to interact with each other