使用 JSON.parseObject(JSON.toJSONString(map), 类型.class)
Map map = JSON.parseObject(JSON.toJSONString(student), Map.class);
Student student = JSON.parseObject(JSON.toJSONString(map), User.class);
例子:
public String getName() {
public void setName(String name) {
public Integer getAge() {
public void setAge(Integer age) {
public String getGender() {
public void setGender(String gender) {
测试类代码:
Student student = new Student();
Map map = JSON.parseObject(JSON.toJSONString(student), Map.class);
map.forEach((key,value)->{
System.out.println("key:" + key + ", value:" + value);
Student student1 = JSON.parseObject(JSON.toJSONString(map), Student.class);
System.out.println("姓名"+student1.getName());
System.out.println("年龄"+student1.getAge());
System.out.println("性别"+student1.getGender());
参考:实体类转 Map_实体类转map_Rock(洛克)的博客-CSDN博客