Skip to content

Commit 83b4e4b

Browse files
深克隆工具类
1 parent a5c20ff commit 83b4e4b

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@
5757
<artifactId>commons-beanutils</artifactId>
5858
<version>1.8.3</version>
5959
</dependency>
60+
<dependency>
61+
<groupId>com.alibaba</groupId>
62+
<artifactId>fastjson</artifactId>
63+
<version>1.2.5</version>
64+
</dependency>
6065

6166
<dependency>
6267
<groupId>commons-collections</groupId>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.object;
2+
3+
import net.sf.json.JSONObject;
4+
5+
/**
6+
* @Auther: Administrator
7+
* @Date: 2019\7\5 0005 0:45
8+
* @Description:
9+
*/
10+
public class CloneTest {
11+
public static void main(String[] args) {
12+
JSONObject paramJson= new JSONObject();
13+
paramJson.put("age",26);
14+
paramJson.put("name","lin");
15+
JSONObject cloneJson= paramJson;
16+
cloneJson.put("age",27);
17+
System.out.println("paramJson:"+paramJson.toString());
18+
System.out.println("cloneJson:"+cloneJson.toString());
19+
}
20+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.object;
2+
3+
import com.alibaba.fastjson.JSONObject;
4+
import org.apache.commons.lang.SerializationUtils;
5+
6+
/**
7+
* @Auther: Administrator
8+
* @Date: 2019\7\5 0005 0:59
9+
* @Description:
10+
*/
11+
public class DeepCloneTest {
12+
public static void main(String[] args) {
13+
JSONObject paramJson= new JSONObject();
14+
paramJson.put("age",26);
15+
paramJson.put("name","lin");
16+
JSONObject cloneJson= (JSONObject)SerializationUtils.clone(paramJson);
17+
cloneJson.put("age",27);
18+
System.out.println("paramJson:"+paramJson.toString());
19+
System.out.println("cloneJson:"+cloneJson.toString());
20+
}
21+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.object;
2+
3+
import net.sf.json.JSONObject;
4+
import org.apache.commons.beanutils.BeanUtils;
5+
6+
import java.lang.reflect.InvocationTargetException;
7+
8+
/**
9+
* @Auther: Administrator
10+
* @Date: 2019\7\5 0005 0:57
11+
* @Description:
12+
*/
13+
public class DeepCloneTest2 {
14+
public static void main(String[] args) throws InvocationTargetException, IllegalAccessException {
15+
JSONObject paramJson= new JSONObject();
16+
paramJson.put("age",26);
17+
paramJson.put("name","lin");
18+
JSONObject cloneJson= new JSONObject();
19+
BeanUtils.copyProperties(cloneJson,paramJson);
20+
cloneJson.put("test",27);
21+
System.out.println("paramJson:"+paramJson.toString());
22+
System.out.println("cloneJson:"+cloneJson.toString());
23+
}
24+
}

0 commit comments

Comments
 (0)