使用maven工具,通过简单方式将map对象转为对象实体,或将对象实体转换为map对象,不用再循环取值赋值操作了!!
直接简单点:
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.4</version>
</dependency>
版本自行在Maven仓库下载即可
使用
// 对象转map
User user = new User();
BeanUtils.setProperty(user, "id", 1);
// 对象转map
Map<String, String> map = BeanUtils.describe(user);
// map转对象
User newUser = new User();
BeanUtils.populate(newUser, map);
结束
有帮助点个赞吧~