zoukankan      html  css  js  c++  java
  • postman中如何传数组

    方法一:

    postman的传参:

    java接收:

    package com.nps.base.xue.xd.groovyEngine
    
    import com.google.gson.Gson
    import com.google.gson.reflect.TypeToken
    import com.nps.common.service.NpsApplicationContextHolder
    import com.nps.data_api.service.impl.NpsDataApiService
    
    import java.lang.reflect.Type
    
    /*
        * @author XueWeiWei
        * @date 2019/8/9 17:24
    */
    class TrainMarshallingUpdateByGKEYGroovy {
        private NpsDataApiService npsDataApiService = NpsApplicationContextHolder.getApplicationContext().getBean("npsDataApiService")
    
    //    public List<Object> execute(Map<Object,Object> param){
    //        List<Object> result = new ArrayList<>()
    //
    //        Map resultMap = new HashMap()
    //
    //        npsDataApiService.exec(param,"train_marshalling_update_by_gkey")
    //
    //        resultMap.put("resultCode","success")
    //
    //        result.add(resultMap)
    //        return result
    //    }
    
    //    public List<Object> execute(List<Map<Object,Object>> param){
    //        List<Object> result = new ArrayList<>()
    //
    //        Map resultMap = new HashMap()
    //
    //        for (int i = 0; i < param.size(); i++) {
    //            npsDataApiService.exec(param[i],"train_marshalling_update_by_gkey")
    //        }
    //
    //        resultMap.put("result","success")
    //        resultMap.put("resultCode","2")
    //
    //        result.add(resultMap)
    //        return result
    //    }
    
        public List<Object> execute(Map<Object,Object> param){
            List<Object> result = new ArrayList<>()
    
            Map queryMap = new HashMap()
            Map resultMap = new HashMap()
    
            //获取数组GKEY
            String GKEYList = param.get("GKEY")
    
            //获取不为空的需要更新的字段
            (param.get("PREARRIVAL_LIST_FK_GKEY1") != null) ? queryMap.put("PREARRIVAL_LIST_FK_GKEY1",param.get("PREARRIVAL_LIST_FK_GKEY1")) : 1 == 1;
            (param.get("PRE_TRAIN_NUMBER") != null) ? queryMap.put("PRE_TRAIN_NUMBER",param.get("PRE_TRAIN_NUMBER")) : 1 == 1;
            (param.get("TRAIN_NUM") != null) ? queryMap.put("TRAIN_NUM",param.get("TRAIN_NUM")) : 1 == 1;
    
            List<Map<Object,Object>> marshallingGKEYList
            Gson gson = new Gson()
            Type type = new TypeToken<List<Map>>(){}.getType()
            marshallingGKEYList = gson.fromJson(GKEYList,type)
    
            //更新
            for (int i = 0; i < marshallingGKEYList.size(); i++) {
                Map marshallingMap;
                marshallingMap = (Map)marshallingGKEYList.get(i)
                queryMap.put("GKEY",marshallingMap.get("GKEY"))
                npsDataApiService.exec(queryMap,"train_marshalling_update_by_gkey")
            }
    
            queryMap.clear()
            resultMap.put("result","success")
            resultMap.put("resultCode","2")
    
            result.add(resultMap)
    
            return result
        }
    }
    

      

    方法二:

    postman传参方式:

     java接收:

    package com.nps.base.xue.xd.groovyEngine
    
    import com.google.gson.Gson
    import com.google.gson.reflect.TypeToken
    import com.nps.common.service.NpsApplicationContextHolder
    import com.nps.data_api.service.impl.NpsDataApiService
    
    import java.lang.reflect.Type
    
    /*
        * @author XueWeiWei
        * @date 2019/8/9 17:24
    */
    class TrainMarshallingUpdateByGKEYGroovy {
        private NpsDataApiService npsDataApiService = NpsApplicationContextHolder.getApplicationContext().getBean("npsDataApiService")
    
    //    public List<Object> execute(Map<Object,Object> param){
    //        List<Object> result = new ArrayList<>()
    //
    //        Map resultMap = new HashMap()
    //
    //        npsDataApiService.exec(param,"train_marshalling_update_by_gkey")
    //
    //        resultMap.put("resultCode","success")
    //
    //        result.add(resultMap)
    //        return result
    //    }
    
    //    public List<Object> execute(List<Map<Object,Object>> param){
    //        List<Object> result = new ArrayList<>()
    //
    //        Map resultMap = new HashMap()
    //
    //        for (int i = 0; i < param.size(); i++) {
    //            npsDataApiService.exec(param[i],"train_marshalling_update_by_gkey")
    //        }
    //
    //        resultMap.put("result","success")
    //        resultMap.put("resultCode","2")
    //
    //        result.add(resultMap)
    //        return result
    //    }
    
        public List<Object> execute(Map<Object,Object> param){
            List<Object> result = new ArrayList<>()
    
            Map queryMap = new HashMap()
            Map resultMap = new HashMap()
    
            //获取数组GKEY
            String GKEYList = param.get("GKEY")
    
            //获取不为空的需要更新的字段
            (param.get("PREARRIVAL_LIST_FK_GKEY1") != null) ? queryMap.put("PREARRIVAL_LIST_FK_GKEY1",param.get("PREARRIVAL_LIST_FK_GKEY1")) : 1 == 1;
            (param.get("PRE_TRAIN_NUMBER") != null) ? queryMap.put("PRE_TRAIN_NUMBER",param.get("PRE_TRAIN_NUMBER")) : 1 == 1;
            (param.get("TRAIN_NUM") != null) ? queryMap.put("TRAIN_NUM",param.get("TRAIN_NUM")) : 1 == 1;
    
            List<Object> marshallingGKEYList
            Gson gson = new Gson()
            Type type = new TypeToken<List<Object>>(){}.getType()
            marshallingGKEYList = gson.fromJson(GKEYList,type)
    
            //更新
            for (int i = 0; i < marshallingGKEYList.size(); i++) {
                queryMap.put("GKEY",marshallingGKEYList.get(i))
                npsDataApiService.exec(queryMap,"train_marshalling_update_by_gkey")
            }
    
            queryMap.clear()
            resultMap.put("result","success")
            resultMap.put("resultCode","2")
    
            result.add(resultMap)
    
            return result
        }
    }
    

      

  • 相关阅读:
    新的
    曾经写过得太监小说3《缱绻修真界》
    Python的from和import用法
    python几个有意思的小技巧
    leetcode 最长回文串
    leetcode-快速排序C++自写
    leetcode 面试题 01.06. 字符串压缩
    leeetcode 剑指 Offer 29. 顺时针打印矩阵
    leetcode 70. 爬楼梯 续
    leetcode 1143. 最长公共子序列-华为
  • 原文地址:https://www.cnblogs.com/xww115/p/11364058.html
Copyright © 2011-2022 走看看