• SpringMVC接收json对象


    请求参数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();
    

      

  • 相关阅读:
    AUDIOqueue 为什么会播放一段时间就听不到声音
    逆序一位数数组求和
    求数组中两数之和等于target的两个数的下标
    iOS获取崩溃日志
    如何看iOS崩溃日志
    关于iOS刷新UI需要在主线程执行
    iOS内置麦克风选择方法
    贝叶斯深度学习-概述
    空间统计(Spatial Statistics)学习笔记(一)— 概述
    重采样技术—Bootstrap
  • 原文地址:https://www.cnblogs.com/JAYIT/p/12981064.html
Copyright © 2020-2023  润新知