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(原始数据, 目标表);
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32