springboot属性注入转化为对象

第一种方式:用spel表达式解析

@Value("#{ T(com.alibaba.fastjson.JSON).parseObject('${train.purchase}')}")
private Map<String, String> purchaseMap;

@Value("#{ T(com.alibaba.fastjson.JSON).parseObject('${train.purchase}')}")
private Map<String, String> map;

第二种方式:获取字符串后,自己解析

return JSON.parseObject(supplier, new TypeReference<LinkedHashMap<String, String>>(){});

第三种方式:自己实现属性编辑器,并注入到环境中

public class DtoEditor extends PropertyEditorSupport {
@Override public void setAsText(String text) throws IllegalArgumentException { String[] str = text.split(","); User user = new User(); user.setName(str[0]); user.setValue(str[1]); setValue(user); } @Override public String getAsText() { return null; } }

 

posted on 2017-03-16 17:31  颓废的悠然  阅读(508)  评论(0编辑  收藏  举报

导航