From 7db0f91c875b27ed2a06ac4ce57654626a29ece0 Mon Sep 17 00:00:00 2001 From: wenc000 <450292408@qq.com> Date: Mon, 24 Aug 2020 17:43:51 +0800 Subject: [PATCH] =?UTF-8?q?zTreeDTO=E7=9A=84clone=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=EF=BC=8C=E6=96=B0=E5=A2=9E=E6=95=B0=E6=8D=AE=E6=B7=B1=E6=8B=B7?= =?UTF-8?q?=E8=B4=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/cm/common/pojo/dtos/ZTreeDTO.java | 13 ++++++- .../com/cm/common/utils/ArrayListUtil.java | 36 +++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 cloud-common/src/main/java/com/cm/common/utils/ArrayListUtil.java diff --git a/cloud-common/src/main/java/com/cm/common/pojo/dtos/ZTreeDTO.java b/cloud-common/src/main/java/com/cm/common/pojo/dtos/ZTreeDTO.java index bd63554..90f94f7 100644 --- a/cloud-common/src/main/java/com/cm/common/pojo/dtos/ZTreeDTO.java +++ b/cloud-common/src/main/java/com/cm/common/pojo/dtos/ZTreeDTO.java @@ -13,7 +13,7 @@ import java.io.Serializable; * @Version: 1.0 **/ @ApiModel -public class ZTreeDTO implements Serializable { +public class ZTreeDTO implements Cloneable, Serializable { private static final long serialVersionUID = 1972916766961693525L; @ApiModelProperty(name = "id", value = "ID") @@ -107,6 +107,17 @@ public class ZTreeDTO implements Serializable { this.title = title; } + @Override + public Object clone() { + ZTreeDTO zTreeDTO = null; + try{ + zTreeDTO = (ZTreeDTO) super.clone(); + }catch (CloneNotSupportedException e) { + e.printStackTrace(); + } + return zTreeDTO; + } + @Override public String toString() { final StringBuilder sb = new StringBuilder("{"); diff --git a/cloud-common/src/main/java/com/cm/common/utils/ArrayListUtil.java b/cloud-common/src/main/java/com/cm/common/utils/ArrayListUtil.java new file mode 100644 index 0000000..26f10d5 --- /dev/null +++ b/cloud-common/src/main/java/com/cm/common/utils/ArrayListUtil.java @@ -0,0 +1,36 @@ +package com.cm.common.utils; + +import java.io.*; +import java.util.ArrayList; +import java.util.List; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: ArrayListUtil + * @Description: 列表工具 + * @Author: WangGeng + * @Date: 2020/8/24 17:25 + * @Version: 1.0 + **/ +public class ArrayListUtil { + + public static List deepClone(List sourceList, Class clazz) { + ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); + try { + ObjectOutputStream out = new ObjectOutputStream(byteOut); + out.writeObject(sourceList); + ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray()); + ObjectInputStream inStream = new ObjectInputStream(byteIn); + List destList = (List) inStream.readObject(); + return destList; + } catch (IOException e) { + e.printStackTrace(); + } catch (ClassNotFoundException e) { + e.printStackTrace(); + } + return null; + } + +}