zoukankan      html  css  js  c++  java
  • 接口接收参数

    app传参:

    {
        "deviceId": "123",
        "labDatas": [{
            "epcId": "E20000198707014902107B3A",
            "times": "7"
        }, {
            "epcId": "E20000198707015202107B00",
            "times": "2"
        }, {
            "epcId": "E20000198707015002107AFF",
            "times": "3"
        }, {
            "epcId": "E20000198707016502108CBA",
            "times": "1"
        }, {
            "epcId": "E20000198707015102107B3B",
            "times": "3"
        }, {
            "epcId": "E200001987070160021083C0",
            "times": "1"
        }, {
            "epcId": "E200001987070156021083BE",
            "times": "2"
        }, {
            "epcId": "E200001987070161021083FC",
            "times": "3"
        }, {
            "epcId": "E20000198707016402108C7E",
            "times": "2"
        }, {
            "epcId": "E20000198707016202108C7D",
            "times": "1"
        }, {
            "epcId": "E200001987070159021083FB",
            "times": "1"
        }, {
            "epcId": "E200001987070157021083FA",
            "times": "1"
        }, {
            "epcId": "E200001987070158021083BF",
            "times": "3"
        }, {
            "epcId": "E20000198707016802108C80",
            "times": "1"
        }, {
            "epcId": "E20000198707016902108CBC",
            "times": "1"
        }],
        "type": "检查"
    }

    后台接收:

    方法一:

    @RequestMapping(value = "up")
        @ResponseBody
        public JSONObject upData(HttpServletRequest request,HttpServletResponse response) throws UnsupportedEncodingException{
            request.setCharacterEncoding("utf-8");
            response.setCharacterEncoding("utf-8");
            response.setContentType("application/json");
            try {
                StringBuffer json = new StringBuffer();
                BufferedReader reader = request.getReader();
                String line = null;
                while((line=reader.readLine())!=null){
                    json.append(line);
                }
                System.out.println("接收到的json数据为----------------->"+json.toString());
            } catch (Exception e) {
                e.printStackTrace();
            }
            return assemblyJson("", Constants.STATUS_SUCCESS, "成功");
        }

    方法二:

    @RequestMapping(value = "up")
    @ResponseBody
    public JSONObject upData(@RequestParam  Map<String, Object> body){
        System.out.println(body);
        return assemblyJson("", Constants.STATUS_SUCCESS, "成功");
    }

    总结:

    前端请求传Json对象则后端使用@RequestParam;

    前端请求传Json对象的字符串则后端使用@RequestBody。

     

  • 相关阅读:
    Oracle 10g AND Oracle 11g手工建库案例--Oracle 11g
    第十七篇:实例分析(1)--初探WDDM驱动学习笔记(八)
    Git权威指南学习笔记(二)Git暂存区
    C++11多线程教学II
    c++ 11 多线程教学(1)
    C++11 多线程 基础
    C++11下的线程池以及灵活的functional + bind + lamda
    intel线程库tbb的使用
    TBB入门
    TTB 基本
  • 原文地址:https://www.cnblogs.com/gjq1126-web/p/11639504.html
Copyright © 2011-2022 走看看