https://blog.csdn.net/alex_xfboy/article/details/88076245
public static void main(String[] args) {
ApplicationContext context = new AnnotationConfigApplicationContext();
LocalDateTime dateTime = LocalDateTime.now();
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
//创建 CustomDateEditor 对象
CustomDateEditor editor = new CustomDateEditor(dateFormat, true);
//注册为日期类型的自定义编辑器
// binder.registerCustomEditor(Date.class, editor);
Person person = new Person();
DataBinder binder = new DataBinder(person, "person");
binder.addCustomFormatter(new DateFormatter());
// 创建用于绑定到对象上的属性对(属性名称,属性值)
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("name", 12);
pvs.add("age", true);
pvs.add("dateTime", "2020-03-26");
binder.bind(pvs);
System.out.println(person.toString());
// 程序打印:Person{name='dmz', age=18}
}
class Person extends FatherPerson {
String name;
Boolean age;
Date dateTime;
public Date getDateTime() {
return dateTime;
}
public void setDateTime(Date dateTime) {
this.dateTime = dateTime;
}
// public LocalDateTime getDateTime() {
// return dateTime;
// }
//
// public void setDateTime(LocalDateTime dateTime) {
// System.out.println(dateTime);
// this.dateTime = LocalDateTime.now();
// }
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Boolean getAge() {
return age;
}
public void setAge(Boolean age) {
this.age = age;
}
@Override
public String toString() {
return "Person{" +
"name='" + name + ''' +
", age=" + age +
", dateTime=" + dateTime +
", fastName=" + fastName +
'}';
}
}



