第一种方式:用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; } }

 

相关文章: