日期:2014-05-18 浏览次数:20791 次
<package name="emp" extends="json-default">有一个action是这么配置的,success的result返回json数据,action中的相应方法fetchEmps是这样的
<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
我的疑惑是Struts2是怎么判断把哪个对象当做json数据返回的,方法里也没有显示把某个要返回的对象放入域啊,相应的action代码为:
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";
}
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";
}