zoukankan      html  css  js  c++  java
  • 对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数据解析成自己需要的对象,来进行相关的操作,通过参数接收操作后的数据,来进行返回码的判断,将返回码显示给上一级查看

  • 相关阅读:
    使用JDBCTemplate执行DQL/DML语句
    spring中JDBCTemplate的简单应用
    Druid数据库连接池工具类
    Same Tree
    Remove Duplicates from Sorted List
    Length of Last Word
    Remove Element
    Remove Duplicates from Sorted Array
    java-StringBuffer更改功能
    java-StringBuffer的删除功能
  • 原文地址:https://www.cnblogs.com/darui/p/9077340.html
Copyright © 2011-2022 走看看