Skip to content

Commit 101815e

Browse files
author
chenhaoxiang
committed
自己写的一个BeanUtils-代码方法详解
1 parent a5d7de3 commit 101815e

15 files changed

Lines changed: 1039 additions & 0 deletions

‎myBeanUtils/.classpath‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.7.0_04"/>
5+
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
6+
<classpathentry kind="output" path="bin"/>
7+
</classpath>

‎myBeanUtils/.project‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>myBeanUtils</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#Thu Aug 25 11:01:52 CST 2016
2+
eclipse.preferences.version=1
3+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
4+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
5+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6+
org.eclipse.jdt.core.compiler.compliance=1.6
7+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
9+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
11+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
12+
org.eclipse.jdt.core.compiler.source=1.6

‎myBeanUtils/README.md‎

Lines changed: 361 additions & 0 deletions
Large diffs are not rendered by default.
2.01 KB
Binary file not shown.
2.65 KB
Binary file not shown.
2.38 KB
Binary file not shown.
2.23 KB
Binary file not shown.
1.73 KB
Binary file not shown.
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package cn.hncu;
2+
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
6+
import org.junit.Test;
7+
8+
import cn.hncu.beanUtils.MyBeanUtils;
9+
import cn.hncu.beanUtils.MyBeanUtils1;
10+
import cn.hncu.domain.Book;
11+
import cn.hncu.domain.User;
12+
13+
public class TestDemo {
14+
15+
@Test
16+
@SuppressWarnings("unchecked")
17+
public void test() {
18+
Map<String, Object> map = new HashMap();
19+
map.put("uuid", "001");
20+
map.put("name", "Jack");
21+
map.put("age", 20);
22+
23+
Map<String, Object> map2 = new HashMap();
24+
map2.put("uuid", "001");
25+
map2.put("name", "红楼梦");
26+
map2.put("inPrice", 20.5);
27+
//数据可能不全
28+
map2.put("num", 123);
29+
try {
30+
User user = MyBeanUtils.populate(User.class, map);
31+
System.out.println(user);
32+
Book book = MyBeanUtils.populate(Book.class, map2);
33+
System.out.println(book);
34+
} catch (ReflectiveOperationException e) {
35+
e.printStackTrace();
36+
}
37+
}
38+
39+
@Test
40+
public void test1() {
41+
Map map = new HashMap();
42+
map.put("uuid", "001");
43+
map.put("name", "Jack");
44+
map.put("age", 20);
45+
46+
Map map2 = new HashMap();
47+
map2.put("uuid", "001");
48+
map2.put("name", "红楼梦");
49+
map2.put("inPrice", 20.5);
50+
//数据可能不全
51+
map2.put("num", 123);
52+
try {
53+
User user = (User) MyBeanUtils1.populate(User.class, map);
54+
System.out.println(user);
55+
Book book = (Book) MyBeanUtils1.populate(Book.class, map2);
56+
System.out.println(book);
57+
} catch (ReflectiveOperationException e) {
58+
e.printStackTrace();
59+
}
60+
}
61+
62+
63+
}

0 commit comments

Comments
 (0)