struts2注解json 配置文件json

result 中一定要 有name 属性和方法中的return对应

1.注解Action中写法:

package cn.damai.subscription.action; 


@ParentPackage("json-default") 
public class TestAction extends BaseAction{

@Action(value="/faq/queryjsonList",results=@Result(type="json",name="jsonlist",params={"includeProperties","rows.*"})) 
public String queryjsonList(){ 
    this.rows = infoService.selectByTitleAndTypeForNormal(title, type); 
    return "jsonlist"; 
}

}

 

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;
}


}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值