Map映射
BeanUtils
支持简单的java.util.Map
和Java Bean的互相转换功能。使用者只需将Map
作为第一个或者第二个参数传入方法中即可。
class Foo {
String name = "foo";
Date date = null;
}
Map<String, Object> map = new HashMap<>();
BeanUtils.copyProperties(foo, map); // mapNull = false
System.out.println(map.get("name")); // "foo"
System.out.println(map.containsKey("date")); // false
BeanUtils.copyProperties(foo, map, true); // mapNull = true
System.out.println(map.containsKey("date")); // true
Last updated