用到的中间工具类型 net.sf.json.JSONObject
//建立一个对象并将 给对象赋值
Student stu = new Student();
stu.setId(1);
stu.setName("张三");
1.实体类转Object
JSONObject json = JSONObject.fromObject(stu);
Object obj = JSONObject.toBean(json,Student.class);
2.Object转实体类
JSONObject objJson = JSONObject.fromObject(obj);
Student stu = (Student) JSONObject.toBean(objJson,Student.class);
Object类型和实体类简单的相互转化
最新推荐文章于 2024-01-02 15:08:42 发布