1.ajax页面即js页面
var nums=[]; //销量数组(实际用来盛放Y坐标值)
$.ajax({
type : "post", //请求的方式,默认为get
async : true, //异步请求(同步请求将会锁住浏览器,用户其他操作必须等待请求完成才可以执行)
url :"/eah-map/exhibition/zxlx.do", //请求发送到TestServlet处,记得带.do,不然路径错误
data : {},
dataType : "json", //返回数据形式为json
success : function(result) {
//请求成功时执行该函数内容,result即为服务器返回的json对象
if (result) {
图表代表的别名.setOption({ //加载数据图表,指定是哪个表
series: [{
// 根据名字对应到相应的系列
name: '设备数量',
data:result
}]
});
}
},
error : function(errorMsg) {
//请求失败时执行该函数
alert("请求数据失败!");
myChart.hideLoading();
}
});
比如这种就是 代表的别名
2.controller页面
@RequestMapping(value = "/zxlx", method = RequestMethod.POST)
@ResponseBody
protected void doPosted(HttpServletRequest request, HttpServletResponse response,MonitoringEquipmentInfo monitoringEquipmentInfo) throws ServletException, IOException {
List<HashMap> list = mes.findMOnthExtends();
ObjectMapper mapper = new ObjectMapper(); //提供java-json相互转换功能的类
String json = mapper.writeValueAsString(list); //将list中的对象转换为Json格式的数组
System.out.println(json);
//将json数据返回给客户端
response.setContentType("text/html; charset=utf-8");
response.getWriter().write(json);
}
value里的别名一定和js页面那里对应起来