Analysis of Two Ways of Obtaining Java Correspondence

1. Identify the corresponding value

// 包装类型map
	Map packMap =  new HashMap();
	// 包装类型数量默认为0,后边根据数量判断是否新增明细
	packMap.put("daiZi", "0");
	packMap.put("zhongYao", "0");
	packMap.put("zhouZhuanXiang", "0");
	packMap.put("bingDai", "0");
	packMap.put("suLiaoDai", "0");
	packMap.put("zhiXiang", "0");
	packMap.put("zhengJian", "0");
	packMap.put("kongZhi", "0");
	
	// WMS包装类型下拉值
	packMap.put("daiZiType", "5");
	packMap.put("zhongYaoType", "7");
	packMap.put("zhouZhuanXiangType", "0");
	packMap.put("bingDaiType", "3");
	packMap.put("suLiaoDaiType", "2");
	packMap.put("zhiXiangType", "1");
	
	// WMS包装下拉转换值->对应托运单细单转换值TMS
	packMap.put("daiZiTypeToValue", "7");
	packMap.put("zhongYaoTypeToValue", "8");
	packMap.put("zhouZhuanXiangTypeToValue", "4");
	packMap.put("bingDaiTypeToValue", "9");
	packMap.put("suLiaoDaiTypeToValue", "10");
	packMap.put("zhiXiangTypeToValue", "2");
	packMap.put("zhengJianTypeToValue", "11");
	packMap.put("kongZhiTypeToValue", "12");

This method is encapsulated by a map, and the value of the'ToValue' key is directly taken when the packaging type is converted.

2. Return the direct conversion value

private Long getConvertValueByHeDan(String type) {
		if("daiZi".equals(type)){
			return 7L;
		}
		if("zhongYao".equals(type)){
			return 8L;
		}
		if("zhouZhuanXiang".equals(type)){
			return 4L;
		}
		if("bingDai".equals(type)){
			return 9L;
		}
		if("suLiaoDai".equals(type)){
			return 10L;
		}
		if("zhiXiang".equals(type)){
			return 2L;
		}
		if("zhengJian".equals(type)){
			return 11L;
		}
		if("kongZhi".equals(type)){
			return 12L;
		}
		return null;
	}

This method is to pass the value and directly return the corresponding value.

Brief analysis

When I wrote the first method, I still felt very fulfilled. But when I suddenly thought of the second method, I felt that the first method was very low. Both methods can achieve the goal, but the second method The method is simple and easy to change and can be viewed directly.

Guess you like

Origin blog.csdn.net/qq_37375667/article/details/100058368