dwz action返回方式的幾種實戰程式碼分享
1、jsp返回
@org.apache.struts2.convention.annotation.Result(name = "add", location = "/vivi/vivigsrp/jsp/vivigsrp/urzinfoadd.jsp"),
2、ftl freemarker返回 //@org.apache.struts2.convention.annotation.Result(name = "success",/*type="freemarker",*/location = "/WEB-INF/templates/test.ftl"), @org.apache.struts2.convention.annotation.Result(name = "success",/*type="freemarker",*/location = "/pages/jsp/main.jsp"), @org.apache.struts2.convention.annotation.Result(name = "input",location = "/WEB-INF/templates/user.ftl")}
tesst: http://localhost:9080/vivigsrp/pages/jsp/login.jsp input page: <html> <body> freemaker歡迎${username}登入系統! <br> ${r'${}'} ${1}<br> <#--迴圈list裡的內容--> <#list list2 as item> ${item.username} <br/>
<#if item.userid=1> <u>${item.userid} </u> <#else> <B>${item.userid}</B> </#if>
<br/> </#list>
3、json返回
@org.apache.struts2.convention.annotation.Result(name = "jsonlist",type="json",params={"root","urzinfojsonlist"}), @org.apache.struts2.convention.annotation.Result(name = "dzjsonlist",type="json",params={"root","dzjsonlist"}), @org.apache.struts2.convention.annotation.Result(name = "input",type="json",params={"root","dwzAjaxResult"})}
public String urzinfodeletebatch() throws NumberFormatException, Exception{ String ids = request.getParameter("ids"); //System.out.println(ids); //String[] id = ids.split(","); //20160901修改dwz.min.js 289 290行ids分隔符 String[] id = ids.split(";"); UrzinfoMapper mapper = (UrzinfoMapper)SpringUtil.getApplicationContext().getBean("urzinfoMapper"); for(int i=0;i<id.length;i++){ mapper.deleteByPrimaryKey((id[i])); } dwzAjaxResult=new DwzAjaxResult("200","刪除成功!","","","","",""); return INPUT; }
public String urzinfojsonlist() throws Exception {
UrzinfoMapper mapper = (UrzinfoMapper)SpringUtil.getApplicationContext().getBean("urzinfoMapper"); urzinfojsonlist=mapper.selectAll();
return "jsonlist" ;
} 4、直接返回不走dwz,比如前臺的圖片流,條碼,jsonlist下拉
public void getcitylist() throws Exception { List<String> dzjsonlist = new ArrayList<String>(); DzMapper mapper = (DzMapper)SpringUtil.getApplicationContext().getBean("dzMapper"); String parentid=request.getParameter("parentid").toString(); dzjsonlist_=(List<Dzcode>)mapper.selectBypid(parentid); for (Dzcode d:dzjsonlist_){ //System.out.println("[\""+d.getCode().toString()+"\",\""+ d.getName()+"\"]"); dzjsonlist.add("[\""+d.getCode().toString()+"\",\""+ d.getName()+"\"]"); } System.out.println(dzjsonlist); response.getWriter().write(dzjsonlist.toString()); response.getWriter().flush(); }