合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
# 组件源码 ``` /** * <b>方法描述:</b> 容器多层次赋值 <br/> * <b>创建者:</b> admin <br/> * <b>创建时间:</b> 2018-05-11 11:54:16 <br/> * * @param con * 入参|容器|{@link java.util.Map} * @param nestKey * 入参|多级key的list,传入String类型标识Map的key,int标识集合下标:如['key1',0]| * {@link com.ylink.ide.trade.runtime.context.JavaList} * @param value * 入参|值|{@link Object} * @return -1 异常<br/> * 0 失败<br/> * 1 成功<br/> */ @Component(label = "容器多层次赋值", style = "判断型", type = "同步组件", comment = "容器中变量多层次嵌套key赋值,如:map的value仍是map等。只支持map/list多层级混合嵌套", version = "1.0.0", deprecated = true, author = "admin", date = "2018-05-17 03:44:24") @InParams(param = {@Param(name = "con", comment = "容器", type = java.util.Map.class), @Param(name = "nestKey", comment = "多级key的list,传入String类型标识Map的key,int标识集合下标:如['key1',0]", type = com.ylink.ide.trade.runtime.context.JavaList.class), @Param(name = "value", comment = "值", type = Object.class)}) @Returns( returns = {@Return(id = "-1", desp = "异常"), @Return(id = "0", desp = "失败"), @Return(id = "1", desp = "成功")}) public static ResultBase P_setNestsValue(Map con, JavaList nestKey, Object value) { if (con == null) return ResultBase.newFailureResult("TPTC2011", "容器不能为空(Null)"); if (nestKey == null || nestKey.isEmpty()) return ResultBase.newFailureResult("TPTC2011", "赋值的参数不能为空"); try { Object m = con; for (int i = 0; i < nestKey.size() - 1; i++) { Object obj = nestKey.get(i); Object subObj = nestKey.get(i + 1); if (obj instanceof String) { if (!(m instanceof Map)) { AppLog.error("key:{},对应的值不是map类型", (i - 1)); return ResultBase.newFailureResult("TPTC2012", "容器中对应的key:" + (i - 1) + ",对应的值不是map"); } if (subObj instanceof String) { // 创建MAP子节点 Object tmpObj = ((Map)m).get((String)obj); if (tmpObj == null || !(tmpObj instanceof Map)) { tmpObj = new JavaContainer(); ((Map)m).put((String)obj, tmpObj); } m = tmpObj; } else if (subObj instanceof Number) { // 创建LIST子节点 Object tmpObj = ((Map)m).get((String)obj); if (tmpObj == null || !(tmpObj instanceof List)) { tmpObj = new JavaList(); ((Map)m).put((String)obj, tmpObj); } m = tmpObj; } else { return ResultBase.newFailureResult("TPTC2016", "多层次赋值下级下标只能传String|Int类型参数"); } } else if (obj instanceof Number) { int index = (Integer)obj; if (!(m instanceof List)) { AppLog.error("key:{},对应的值不是List类型", (i - 1)); return ResultBase.newFailureResult("TPTC2014", "容器中对应的key:" + (i - 1) + ",对应的值不是List"); } List list = (List)m; while (list.size() <= index) { list.add((subObj instanceof String) ? new JavaContainer() : new JavaList()); } m = list.get(index); } else { return ResultBase.newFailureResult("TPTC2015", "多层次赋值当前下标只能传String|Int类型参数"); } } Object lastKey = nestKey.get(nestKey.size() - 1); if (lastKey instanceof String) { if (!(m instanceof Map)) { AppLog.error("key:{},对应的值不是map类型", (nestKey.size() - 2)); return ResultBase.newFailureResult("TPTC2017", "容器中对应的key:" + (nestKey.size() - 2) + ",对应的值不是map"); } ((Map)m).put((String)lastKey, value); } else if (lastKey instanceof Number) { int index = (Integer)lastKey; if (!(m instanceof List)) { AppLog.error("key:{},对应的值不是List类型", (nestKey.size() - 2)); return ResultBase.newFailureResult("TPTC2018", "容器中对应的key:" + (nestKey.size() - 2) + ",对应的值不是List"); } while (((List)m).size() <= index) { ((List)m).add(null); } ((List)m).remove(index); ((List)m).add(index, value); } else { return ResultBase.newFailureResult("TPTC2016", "叶节点下标只能传String|Int类型参数"); } } catch (Exception e) { AppLog.error("容器多层次赋值异常:{}", e); return ResultBase.newExceptionResult("TPTC2019", "容器多层次赋值异常:" + AppLog.errorMsg(e)); } return ResultBase.newSuccessResult(); } ``` # 交易中组件使用方式 ![](https://img.kancloud.cn/00/e6/00e67174c663b467bdaa08034ffde079_1867x891.png) # 参数说明及示例 ## 入口参数 容器:一个 Map 对象,示例: `__INNER__` 多级key的list,传入String类型标识Map的key,int标识集合下标:如['key1',0]:key 列表,示例: `["key1",0,"key2",1,"key3",2]` 值:给 key 赋值,示例: `["v1","v2"]`