【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));
        }
    }
    。。。。。。
}
相关推荐
学习同学几秒前
C++ 初阶总复习 (16~30)
开发语言·c++
五行星辰3 分钟前
SpringBoot集成Logback终极指南:从控制台到云端的多维日志输出
java·后端
luoluoal4 分钟前
java项目之基于ssm的医院门诊挂号系统(源码+文档)
java·mysql·mybatis·ssm·源码
Felven4 分钟前
C. The Legend of Freya the Frog
c语言·开发语言
Yvsanf15 分钟前
C++细节知识for面试
开发语言·c++
郭涤生22 分钟前
全书测试:《C++性能优化指南》
开发语言·c++·笔记·性能优化
刚正的热带野猪25 分钟前
文件格式校验方案
java·后端
敖正炀29 分钟前
java线程详解
java
Re27532 分钟前
springboot源码分析--初始加载配置类
java·spring boot
五行星辰33 分钟前
SpringBoot集成Log4j2终极指南:从基础配置到性能调优
java·后端