【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));
        }
    }
    。。。。。。
}
相关推荐
nlog3n7 分钟前
Go语言交替打印问题及多种实现方法
开发语言·算法·golang
kaixin_learn_qt_ing11 分钟前
Golang
开发语言·后端·golang
ddd...e_bug14 分钟前
Shell和Bash介绍
开发语言·bash
C4程序员1 小时前
Java百度身份证识别接口实现【配置即用】
java·开发语言
unityのkiven1 小时前
C++中的虚表和虚表指针的原理和示例
开发语言·c++
炒空心菜菜1 小时前
MapReduce 实现 WordCount
java·开发语言·ide·后端·spark·eclipse·mapreduce
(・Д・)ノ1 小时前
python打卡day27
开发语言·python
zy happy1 小时前
搭建运行若依微服务版本ruoyi-cloud最新教程
java·spring boot·spring cloud·微服务·ruoyi
芯眼2 小时前
STM32启动文件详解(重点)
java·开发语言·c++·stm32·单片机·mybatis
愚润求学2 小时前
【Linux】动静态库链接原理
linux·运维·服务器·开发语言·笔记