struts2注解json 配置文件json
1.注解Action中写法:
package cn.damai.subscription.action;
import java.io.IOException;
import java.util.List;
import
org.apache.struts2.convention.annotation.Action;
import
org.apache.struts2.convention.annotation.ParentPackage;
import
org.apache.struts2.convention.annotation.Result;
import
org.apache.struts2.convention.annotation.Results;
@ParentPackage("json-default")
public class TestAction extends
BaseAction{
private InfoService infoService;
private List<InfoNormalQues> rows;
private
List<InfoQuesType> typeList;
private String title;
private
Long type;
private InfoNormalQues faq;
private String result;
private String userName;
@Action(value="/faq/queryjsonList",results=@Result(type="json",name="jsonlist",params={"includeProperties","rows.*"}))
public String queryjsonList(){
this.rows =
infoService.selectByTitleAndTypeForNormal(title, type);
return "jsonlist";
}
public void setInfoService(InfoService
infoService) {
this.infoService = infoService;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public Long getType() {
return type;
}
public void setType(Long type) {
this.type = type;
}
public
List<InfoQuesType> getTypeList() {
return typeList;
}
public void setTypeList(List<InfoQuesType>
typeList) {
this.typeList = typeList;
}
public List<InfoNormalQues> getRows() {
return rows;
}
public void setRows(List<InfoNormalQues> rows) {
this.rows = rows;
}
public InfoNormalQues
getFaq() {
return faq;
}
public void
setFaq(InfoNormalQues faq) {
this.faq = faq;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result =
result;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
}
2.在配置文件中实现设置的写法:
<struts>
<package name="qp"
extends="json-default">
<!-- 通知单受理 -->
<action
name="noticebill_*" class="noticebillAction" method="{1}">
<!--
根据手机查询客户 -->
<result name="findCustomerByTelephoneSUCCESS"
type="json">
<param
name="root">result</param>
</result>
<!-- 业务受理
-->
<result name="saveSUCCESS"
>/WEB-INF/pages/qupai/noticebill_add.jsp</result>
<!--
人工调度,查询操作 -->
<result
name="findnoassociationsSUCCESS" type="json">
//action中对应的方法
public String
findnoassociations(){
List<NoticeBill> noticeBills =
noticeBillService.findnoassociations();
ActionContext.getContext().put("noticeBills", noticeBills);
return
"findnoassociationsSUCCESS";
}
<param name="root">noticeBills</param>
<param
name="includeProperties">
\[\d+\]\.id,
\[\d+\]\.delegater,
\[\d+\]\.telephone,
\[\d+\]\.pickaddress,
\[\d+\]\.product,
\[\d+\]\.pickdate
</param>
</result>
<result
name="pageQuerySUCCESS" type="json">
<param
name="root">pageResponseBean</param>
<param
name="includeProperties">
total,
rows\[\d+\]\.id,
rows\[\d+\]\.arrivecity,
rows\[\d+\]\.product,
rows\[\d+\]\.num,
rows\[\d+\]\.weight,
rows\[\d+\]\.floadreqr
</param>
</result>
</action>
</package>
</struts>
对应的类文件:
public class PageResponseBean {
private long total ; // 总记录数
private
List rows ; // 当页的数据记录
public long getTotal() {
return
total;
}
public void setTotal(long total) {
this.total =
total;
}
public List getRows() {
return rows;
}
public void
setRows(List rows) {
this.rows = rows;
}
}
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。