Apollo配置枚举项,java解析成value集合

一、apollo配置

order.commodity.unit =
[{"desc":"吨","value":"t"},{"desc":"磅","value":"lb"},{"desc":"克","value":"g"},{"desc":"千克","value":"Kg"},{"desc":"公里","value":"Km"},{"desc":"千米","value":"Km"},{"desc":"米","value":"m"},{"desc":"升","value":"l"},{"desc":"立方米","value":"m³"},{"desc":"平方米","value":"㎡"}]

二、java获取

 @Value("${order.commodity.unit}")
    private String commodityUnit;

三、程序解析

    private List getUnitList() {
        List unit = new ArrayList<>();
        JSONArray parseArray = JsonUtil.parseJsonArray(commodityUnit);
        for (int i = 0; i < parseArray.size(); i++) {
            String value = (String) parseArray.getJSONObject(i).get("value");
            unit.add(value);
        }
        return unit;
    }

你可能感兴趣的:(intellij-idea)