<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.4</version>
</dependency>
public class App {
static {
ConvertUtils.register(new Converter()
{
@SneakyThrows
public Object convert(Class type, Object value)
{
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
return simpleDateFormat.parse(value.toString());
}
}, Date.class);
}
public static void main(String[] args) throws NoSuchAlgorithmException, InvocationTargetException, IllegalAccessException {
HashMap map= new HashMap<String,String>();
map.put("name","张三");
map.put("age","11");
map.put("date","2020-09-09");
Person person=new Person();
BeanUtils.populate(person,map);
System.out.println(person);
}
}