后台代码:
@RequestMapping(value = "getServerDevice")
@ResponseBody
public String getServerDevice(
HttpServletRequest request,
HttpServletResponse response,
@ModelAttribute ServerDevice inputData,
ModelMap modelMap){
String siteCode = inputData.getSiteCode();
List<ServerDevice> serverDeviceList = serverDeviceService.getResultBySiteCode(siteCode);
Gson gson = new Gson();
String retString = gson.toJson(serverDeviceList);
System.out.println(retString + "aaaaaa");
return retString;
}
json数据:
[{"deviceId":"5c4b907fb722413b801728f39eb5885e","siteCode":"1","siteName":"明尼苏达小区","localDeviceId":5,"localUploadDate":"Jun 24, 2019 4:00:00 PM","deviceAlarm":"null","deviceAlarmNum":0,"serverThemoList":[],"serverWaterList":[],"serverSmokeList":[],"serverHumidityList":[],"deviceNum":4,"deviceStatus":"OK","deviceAlarmLevel":1,"createdDate":"Jun 24, 2019 4:00:37 PM"}]aaaaaa
前台ajax代码:
$.ajax({
type : "post",
url : projectName + "/sensors/mobile/getServerDevice",
data : inputData,
dataType : "json",
async : false,
success: function (data)
{
var obj = JSON.parse(data);
console.log(obj[0].deviceAlarmLevel + " dddd");//根据实际业务需求,改为遍历读取即可。
}
});