日期:2014-05-18  浏览次数:20728 次

一直很困action中返回type为json类型的数据
<package name="emp" extends="json-default">
<action name="fetchEmps" class="empAction" method="fetchEmps">
<result name="success" type="json">
<param name="ignoreHierarchy">false</param>
<param name="root">pagination</param>
</result>
</action>
            </package
有一个action是这么配置的,success的result返回json数据,action中的相应方法fetchEmps是这样的


public String fetchEmps(){
    int count = this.empService.countAll();
    this.pagination = new Pagination(this.page, Integer.valueOf(count), this.limit.intValue());
    List ps = this.empService.listAll(this.pagination.getPage().intValue(), this.pagination.getPageSize());
    this.pagination.setDatas(ps);
    return "success";
  }
我的疑惑是Struts2是怎么判断把哪个对象当做json数据返回的,方法里也没有显示把某个要返回的对象放入域啊,相应的action代码为:

import xxxxxxxx;
@Controller("empAction")
@Scope("prototype")
public class EmpAction extends BaseAction
{
  private static final long serialVersionUID = 1L;
  private IEmpService empService;
  private String newEmp;
  private String userName;
  private boolean exists;

  @Autowired
  @Required
  public void setEmpService(IEmpService empService)
  {
    this.empService = empService;
  }

  @JSON(serialize=false)
  public IEmpService getEmpService() {
    return this.empService;
  }

  public String fetchEmps()
  {
    int count = this.empService.countAll();
    this.pagination = new Pagination(this.page, Integer.valueOf(count), this.limit.intValue());
    List ps = this.empService.listAll(this.pagination.getPage().intValue(), this.pagination.getPageSize());
    this.pagination.setDatas(ps);
    return "success";
  }

------解决方案--------------------
<param name="root">pagination</param>
返回pagination属性