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
        }
    }
    

      

  • 相关阅读:
    使用python脚本自动创建pip.ini配置文件
    Windows 安全软件集
    配置 vim 编辑器
    (转)linux下和云端通讯的例程, ubuntu和openwrt实验成功(一)
    转 10 个最佳的 Node.js 的 MVC 框架
    转-基于NodeJS的14款Web框架
    (转) [it-ebooks]电子书列表
    (原创) alljoyn物联网实验之手机局域网控制设备
    (原创)天气又转热了,我给她做了个智能小风扇
    Alljoyn瘦客户端库介绍(官方文档翻译 下)
  • 原文地址:https://www.cnblogs.com/xww115/p/11364058.html
Copyright © 2011-2022 走看看