【JAVA:list中再定义一个list对象,循环赋值不同的list数据,出现追加重复数据问题】

问题描述:

list中再定义一个list对象,循环赋值不同的list数据,结果全部都累加到每条数据中了,每条数据中都出现重复数据。

问题解决:

1.创建树结构方法信息

2.创建一个新的 List 对象,避免引用问题

3.使用 GongkuangMethodDictVo 的拷贝构造函数

java 复制代码
public class PlanSchemeProductionGongkuangStatus
{
	。。。。。。
    /** 创建树结构方法信息 */
    private List<GongkuangMethodDictVo> gongkuangMethodDicList;

    public List<GongkuangMethodDictVo> getGongkuangMethodDicList() {
        return gongkuangMethodDicList;
    }

    public void setGongkuangMethodDicList(List<GongkuangMethodDictVo> gongkuangMethodDicList) {
        // 创建一个新的 List 对象,避免引用问题
        this.gongkuangMethodDicList = new ArrayList<>();
        for (GongkuangMethodDictVo gongkuangMethodDictVo : gongkuangMethodDicList) {
            // 使用 GongkuangMethodDictVo 的拷贝构造函数
            this.gongkuangMethodDicList.add(new GongkuangMethodDictVo(gongkuangMethodDictVo));
        }
    }
    。。。。。。
}
相关推荐
charlie11451419117 小时前
现代Qt开发教程(新手篇)2.3——QImage、QPixmap、QIcon 图像处理基础
开发语言·图像处理·qt
范范@17 小时前
python基础-函数
开发语言·python
特种加菲猫18 小时前
从零开始手撕AVL树:详解插入、平衡因子更新与四种旋转
开发语言·c++
oddsand118 小时前
Redis网络模型
java·数据库·redis
皮卡祺q18 小时前
【redies0-导论】分布式系统的演进-引进redis原因
java·数据库·redis
roman_日积跬步-终至千里18 小时前
如何分析复杂架构:一套真正能落地的方法
java·开发语言·架构
geovindu18 小时前
go: Semaphore Pattern
开发语言·后端·设计模式·golang·企业级信号量模式
武子康18 小时前
Java-02 深入浅出MyBatis 3 快速入门:环境配置、项目创建与 CRUD 操作
java·后端
Don.TIk18 小时前
ChapterOne-搭建项目骨架
java·spring·spring cloud·mybatis
Don.TIk18 小时前
ChaperTwo-整合 SaToken 实现 JWT 登录功能
java·开发语言