问题:Easyui-datagrid-pagination结合Struts2使用时不显示正确的Total,而是显示返回的list的数量?
如图所示:
从action传total参数过来,这边并不显示实际的total,但是其他地方的total是可以传的:
对比了两个方法的区别;
(1)、可以传total的方法;
public String selectPaginationAndFddbr() {
int _rows = IntegerUtil.changeString2Int(request.getParameter("rows"));
e.setDjgljg(this.ssjg);
this.total = tStglBgJbxxService.selectCountAndFddbr(e);
this.rows = tStglBgJbxxService.selectPaginationAndFddbr(e, _rows, this.page);
return SUCCESS;
}
(2)、不可以传total的方法;
public String selectTzPagination() {
int _rows = IntegerUtil.changeString2Int(request.getParameter("rows"));
e.setDjgljg(this.ssjg);
this.total = tStglBgJbxxService.selectTzCount(e);
this.bgTzList = tStglBgJbxxService.selectTzPagination(e, _rows, this.page);
return SUCCESS;
}
定义的类的属性
private List<TStglBgJbxxEntity> rows = new ArrayList<TStglBgJbxxEntity>();
private TStglBgJbxxEntity e = new TStglBgJbxxEntity();
private int total = 0;
private List<Map<String, Object>> bgTzList = new ArrayList<Map<String, Object>>();
private JSONObject result;
发现两个list的泛型不一致,一个Map,一个Entity;应该是这个方面的问题导致的,所以将selectTzPagination改为
public String selectTzPagination() {
int _rows = IntegerUtil.changeString2Int(request.getParameter("rows"));
e.setDjgljg(this.ssjg);
this.total = tStglBgJbxxService.selectTzCount(e);
this.bgTzList = tStglBgJbxxService.selectTzPagination(e, _rows, this.page);
Map<String, Object> jsonMap = new HashMap<String, Object>();
jsonMap.put("total", total);
jsonMap.put("rows", bgTzList);
result = JSONObject.fromObject(jsonMap);//格式化result 一定要是JSONObject
return SUCCESS;
}
_struts.xml文件中配置文件里的写法如下;
<action name="selectPaginationAndFddbr" class="TStglBgJbxxAction" method="selectPaginationAndFddbr">
<result name="success" type="json">
<param name="contentType">text/html</param>
<param name="excludeNullProperties">true</param>
</result>
</action>
<action name="selectTzPagination" class="TStglBgJbxxAction" method="selectTzPagination">
<result name="success" type="json">
<param name="contentType">text/html</param>
<param name="excludeNullProperties">true</param>
<param name="root">result</param>
</result>
</action>
发现total可以接收成功了;