92、使用beanUtil方法把Map赋值给实体类
import org.apache.commons.beanutils.BeanUtils;
public class Main {
public static void main(String[] args) {
Map<String, String> map = new HashMap<>();
map.put("name", "John");
map.put("age", "25");
Person person = new Person();
try {
BeanUtils.populate(person, map);
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(person.getName());
System.out.println(person.getAge());
}
public static class Person {
private String name;
private int age;
}
}
BeanUtils.copyProperties(目标数据,原原始数据)
BeanUtils.copyProperties(原始数据, 目标表);