• 对JSON数据的解析(数据推送接口)


    package com.liuqi.www;
    
    import java.util.HashMap;
    import java.util.Map;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.web.bind.annotation.PostMapping;
    import org.springframework.web.bind.annotation.RequestBody;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.ResponseBody;
    
    @Controller("TestController")
    @RequestMapping(value = "/testController",method = RequestMethod.POST)
    public class TestController{
        
        @RequestMapping(value="/test",method = RequestMethod.POST)
        @ResponseBody
        public Map<String,Object> test(@RequestBody Map<String,Object> parameter){
            //请求的数据相关信息
            Map<String,String> head = (Map<String,String>)parameter.get("head");
            
            //js端生成的请求流水号
            String reqId = head.get("reqId");
            
            //请求时间
            String times = head.get("times");
            
            //请求从哪个功能点过来的
            String compId = head.get("compId");
            
            //存放数据描述信息
            Map<String,Object> info = (Map<String,Object>)parameter.get("info");
            
            //数据类型
            String dataType = (String)info.get("dataType");
            
            //操作类型
            String opType = (String)info.get("opType");
            
            //存放数据的对象
            Object date = info.get("date");
            
            //做处理
            
            
            //返回结果
            Map<String,Object> result = new HashMap<>();
            
            Map<String,Object> resultHead = new HashMap<>();
            
            //给head里面放数据
            
            Map<String,Object> resultInfo = new HashMap<>();
            
            //给info里面放数据
            
            result.put("head", resultHead);
            result.put("info", resultInfo);
            return result;
        }
        
    }

    将JSON数据解析成自己需要的对象,来进行相关的操作,通过参数接收操作后的数据,来进行返回码的判断,将返回码显示给上一级查看

  • 相关阅读:
    洛谷 P1200.[USACO1.1]你的飞碟在这儿Your Ride Is Here
    洛谷 P1055.ISBN号码
    洛谷 P1567.统计天数
    洛谷 P2141.珠心算测验
    洛谷 P1428.小鱼比可爱
    洛谷 P1427.小鱼的数字游戏
    洛谷 P1047.校门外的树
    洛谷 P1046.陶陶摘苹果
    洛谷 P1980.计数问题
    洛谷 P1424.小鱼的航程(改进版)
  • 原文地址:https://www.cnblogs.com/darui/p/9077340.html
Copyright © 2020-2023  润新知