api controller 接口接收json字符串参数

时间:2022-06-11 13:37:27

api controller 接口接收json字符串参数

{"data":{"alarmRepeatTimes":2,"currentMode":1,"moduleResetTimeout":3,"otherInterval":4,"statusInterval":5},"devEuiList":["3237383162378A01","3238313953367222"]}

@RequestMapping(value ="setting/olc",method = RequestMethod.POST)
@ResponseBody
public ResponseResult multipleSetting(@RequestBody String body){
LogUtils.infoLog(getClass().getSimpleName(), "multipleSetting", logger,
LogUtils.ActionDirection.DIRECTION_LOCAL, "multipleSetting settingDto :" , Json.toJson(body));
JSONObject jb = Json.fromJson(body,JSONObject.class);
String dataJson = jb.getAsString("data");
SettingDto settingDto = Json.fromJson(dataJson,SettingDto.class);
TbSetting tbSetting = new TbSetting();
tbSetting.setCurrentMode(settingDto.getCurrentMode());
tbSetting.setStatusUpdateInterval(settingDto.getStatusInterval());
tbSetting.setOtherUpdateInterval(settingDto.getOtherInterval());
tbSetting.setAlarmRepeatTime(settingDto.getAlarmRepeatTimes());
tbSetting.setModuleReset(settingDto.getModuleResetTimeout());
tbSetting.setCreateTime(new Date());
List<String> devlist = (List<String>)jb.get("devEuiList"); adminService.multipleSetting(tbSetting,devlist);
ResponseResult responseResult = new ResponseResult();
return responseResult;
}