这是action
public String staffListQuery() {
logger.debug("staffListQuery");
if (pageNo == CodeConstants.PAGE_DEFU) {
pageNo = CodeConstants.PAGENO_INIT;
}
if (pageSize == CodeConstants.PAGE_DEFU) {
pageSize = CodeConstants.PAGESIZE_INIT;
}
try {
String operatorCode = (String) getSession()
.getAttribute("UserCode");
Page page = staffManageService.queryStaffRecord(
staffManageCondition, pageNo, pageSize, operatorCode,
exportType);
/** 将结果值以JSON方式读取 */
writeJSONData(page, "PERSONID","PERSONNAME","COMNAME","TEAMNAME","VALIDSTATUS","VERIFYSTATUS","OPERATETIMES","OPERATETYPE","VERIFYTYPE");
} catch (Exception e) {
this.writeJSONMsg(e.getMessage());
}
// System.out.println(JSONArray.fromObject(writeJSONData.jsonObject));
return null;
}
这是json
public void writeJSONData(Page page, String... args) {
try {
Assert.notEmpty(args);
List dataList = new Vector();
List list = page.getResult();
int size = args.length;
for (Iterator iter = list.iterator(); iter.hasNext(); ) {
Object element = iter.next();
Map dataMap = new HashMap(size);
for (int i = 0; i < size; i++) {
Object value = null;
if (args[i].indexOf('.') > -1) {
String[] arrArg = StringUtils.split(args[i], '.');
value = element;
for (int j = 0; j < arrArg.length - 1; j++) {
value = PropertyUtils.getProperty(value, arrArg[j]);
if(value != null){
value = PropertyUtils.getProperty(value,arrArg[(j + 1)]);
}
}
} else {
value = PropertyUtils.getProperty(element, args[i]);
}
dataMap.put(args[i], fixValueForJSON(value));
}
dataList.add(dataMap);
}
JSONObject jsonObject = new JSONObject();
jsonObject.put("totalRecords", page.getTotalCount());
jsonObject.put("data", JSONArray.fromObject(dataList));
renderHtml(jsonObject.toString());
} catch (Exception e) {
e.printStackTrace();
writeJSONMsg(e.getMessage());
}
}
JSON有值
这里没值