zTreeDTO的clone实现,新增数据深拷贝

This commit is contained in:
wenc000 2020-08-24 17:43:51 +08:00
parent 5379fab60a
commit 7db0f91c87
2 changed files with 48 additions and 1 deletions

View File

@ -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("{");

View File

@ -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 <T extends Serializable> List<T> deepClone(List<? extends Serializable> sourceList, Class<T> 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<T> destList = (List<T>) inStream.readObject();
return destList;
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return null;
}
}