方法一:
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 } }