欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

使用 Java 复制列表,无需 BeanUtils.copyProperties

最编程 2024-04-01 19:11:12
...

1.List不起作用(单个对象拷贝有用,list没有用)

cn.hutool.core.bean.BeanUtils.copyProperties(a, b);

org.springframework.beans.BeanUtils.copyProperties(a, b);

2.有效(使用JSONObject 先转成字符串再转成List对象)

List<User> users =  com.alibaba.fastjson.JSONObject.parseObject(JSONObject.toJSONString(userList), new TypeReference<List<User>>() {
});

推荐阅读