3
Maps에서 BeanUtils setProperty 메서드를 사용하려면 어떻게해야합니까?지도가있는 BeanUtils
예 :이 메서드는 다음과 같습니다. public void setAddress (String type, Address address); 다음을 사용하여 설정할 수 있습니다. BeanUtils.setProperty (beanObject, "address (home)", addressObject);
하지만 설정하려는 객체가 맵인 경우 가능합니까? 방법?
이public static class Bean{
private Map<String, String> data = new HashMap<String, String>();
public Map<String, String> getData(){
return data;
}
public void setData(final Map<String, String> data){
this.data = data;
}
}
public static void main(final String[] args) throws Exception{
final Bean bean = new Bean();
// assign the foo key of the data property to the value 'bar'
BeanUtils.setProperty(bean, "data(foo)", "bar");
System.out.println(bean.data);
}
출력 :이
{foo는 = 바}
이 무엇입니까 – fmaste