postman中如何传数组

方法一:

postman的传参:

postman中如何传数组_第1张图片

 

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 execute(Map param){
//        List 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 execute(List> param){
//        List 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 execute(Map param){
        List 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> marshallingGKEYList
        Gson gson = new Gson()
        Type type = new TypeToken>(){}.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传参方式:

postman中如何传数组_第2张图片

 

 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 execute(Map param){
//        List 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 execute(List> param){
//        List 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 execute(Map param){
        List 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 marshallingGKEYList
        Gson gson = new Gson()
        Type type = new TypeToken>(){}.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
    }
}
 
    
   

  

转载于:https://www.cnblogs.com/xww115/p/11364058.html

你可能感兴趣的:(postman中如何传数组)