请求参数json格式:
{ "request": { "controlinfo ": { "sysCode": "xxx", "password": "xxx", "msgId": "xxx", "time": "xxx" }, "param": { } } }
解析:
/** * @return 活动创建 */ @RequestMapping(value = "/add", produces = "text/plain;charset=utf-8") public String taskInfoAdd(HttpServletRequest request, @RequestBody String reqStr) { logger.info("=====TASKINFO ADD======"); logger.info("REQUEST DATA IS String:" + reqStr); ResponseInfo resultInfo = new ResponseInfo(); ThreadLocalVariable.setTenantId(TENANT_ID); try { JSONObject reqInfo = new JSONObject(reqStr); JSONObject requestInfo = reqInfo.getJSONObject("request"); JSONObject controlinfo = requestInfo.getJSONObject("controlinfo"); // 校验权限信息 boolean isValid = authUtil.validateAuth(controlinfo); String tenantId = TENANT_ID; if (isValid) { // String param = requestInfo.optString("param"); // JSONObject taskInfoObject = new JSONObject(param); JSONObject taskInfoObject = requestInfo.getJSONObject("param"); // 组装信息 TObTask taskInfo = new TObTask(); try { taskInfo = this.buildTaskAddInfo(taskInfoObject); } catch (Exception e) { throw new LengthException(); } } public TObTask buildTaskAddInfo(JSONObject param) throws Exception { TObTask taskInfo = new TObTask(); if (notEmptyStr(param.optString("TASK_NAME"))) { taskInfo.setTaskName(param.optString("TASK_NAME")); } else { throw new Exception("任务名称不能为空"); }
返回参数:
resultInfo.setCode(-1); resultInfo.setReason("权限校验失败"); } } catch (Exception e) { this.buildError(resultInfo, e); } return new JSONObject(resultInfo).toString();