Ajax Java异步请求返回实体类
程序员文章站
2024-01-25 19:48:40
...
Ajax 异步请求实例:
/**
* @Description: 行业项目统计 自贸区各行业数据统计\近半年各行业总投资走势
*/
@RequestMapping(value = "/m1", method = { RequestMethod.POST, RequestMethod.GET })
@ResponseBody
public AjaxResult m1() {
AjaxResultList res = AjaxResultList.ok();
Map result = new HashMap<String, Object>();
try {
// 列表
List<Map<String, Object>> hytjList = iZhbsTjfxService.queryHytj(djrqStart, djrqEnd);
// 柱状图
List<String> sixMonthList = FxjcUtils.querySixMonth(new SimpleDateFormat("YYYY-MM").format(new Date()));
List<Map<String, Object>> hytjZxList = iZhbsTjfxService.queryHytj(sixMonthList.get(0));
// 折线图数据组织
for (int i = 1; i < sixMonthList.size(); i++) {
List<Map<String, Object>> hytjZxListN = iZhbsTjfxService.queryHytj(sixMonthList.get(i));
for (int k = 0; k < hytjZxList.size(); k++) {
hytjZxList.get(k).put("XMZTZ" + (i + 1), SetHaspMap.setString(hytjZxListN.get(k).get("XMZTZ")));
}
}
result.put("hytjList", hytjList);
result.put("hytjZxList", hytjZxList);
result.put("sixMonthList", sixMonthList);
res.setData(result);
return res;
} catch (Exception e) {
return AjaxResultList.fail("行业项目统计 自贸区各行业数据统计\\近半年各行业总投资走势查询出错:" + e.getMessage());
}
}
返回结果实体类:
package com.alphasta.syfx.vo;
public class AjaxResult {
public static int CODE_OK = 200;
public static int CODE_ERROR = 501;
public static int CODE_NOTLOGIN = 101;
public static int CODE_LOGINTIMEOUT = 102;
public static int CODE_REDLOAD = 103;
public static int CODE_UNKNOWN = 301;
private int code = CODE_OK;
private String message;
private Object data;
public static AjaxResult ok() {
AjaxResult ajax = new AjaxResult();
ajax.setCode(AjaxResult.CODE_OK);
return ajax; }
public static AjaxResult ok(Object obj) {
AjaxResult ajax = new AjaxResult();
ajax.setCode(AjaxResult.CODE_OK);
ajax.setData(obj);
return ajax; }
public static AjaxResult fail() {
AjaxResult ajaxResult = new AjaxResult();
ajaxResult.setCode(AjaxResult.CODE_ERROR);
return ajaxResult; }
public static AjaxResult fail(String message) {
AjaxResult ajaxResult = new AjaxResult();
ajaxResult.setCode(AjaxResult.CODE_ERROR);
ajaxResult.setMessage(message);
return ajaxResult; }
public static AjaxResult authc(String message) {
AjaxResult ajaxResult = new AjaxResult();
ajaxResult.setCode(AjaxResult.CODE_NOTLOGIN);
ajaxResult.setMessage(message);
return ajaxResult; }
public Object getData() {
return data; }
public void setData(Object data) {
this.data = data; }
public int getCode() { return code; }
public void setCode(int code) { this.code = code; }
public String getMessage() { return message; }
public void setMessage(String message) { this.message = message; }}
下一篇: 成员变量的反射实例