我们建一个简单的表如下:
+-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | id | varchar(32) | | PRI | | | | name | varchar(80) | YES | | NULL | | | sex | char(1) | YES | | NULL | | | age | int(11) | YES | | NULL | | +-------+-------------+------+-----+---------+-------+
manager的接口
1package com.martin.pdo;
2
3import java.util.List;
4
5/**
6 * @author martin.xus
7 */
8public interface UserManager {
9 public User load(String id);
10
11 public List loadByName(String name);
12
13 public void add(User user);
14
15 public void remove(User user);
16}
17
2
3import java.util.List;
4
5/**
6 * @author martin.xus
7 */
8public interface UserManager {
9 public User load(String id);
10
11 public List loadByName(String name);
12
13 public void add(User user);
14
15 public void remove(User user);
16}
17
User,在这里,我们的user已经不在是简单的getter&setter,我们引用了一个manager的对象
并且通过spring注入给它,供它使用,这样我们需要操作用户时,就如下一样
添加新用户
1User user = (User) context.getBean("user");
2User _u1 = new User();
3//
4user.getManager().add(_u1);
5
读取用户1User _u2 = (User) user.getManager().loadByName("martin xus").get(0);
让User带上manager的功能,这样,我们便不再需要主动的去声明manager。
相对而言,如果我们只是在domain object种getter&setter,就需要如下。
1UserManager userManager = (userManager ) context.getBean("userManager ");
2userManager.saveUser(_u1);
2userManager.saveUser(_u1);
整代码如下:
1package com.martin.pdo;
2
3import java.io.Serializable;
4
5/**
6 * @author martin.xus
7 * @hibernate.class table="t_user"
8 * @spring.bean name="user"
9 * @spring.property name="manager" ref="userManager"
10 */
11public class User implements Serializable {
12
13 /**
14 * @hibernate.id generator-class="uuid.hex"
15 * length="32"
16 * column="user_id"
17 */
18 private String id;
19
20 /**
21 * @hibernate.property column="user_name"
22 * length="80"
23 */
24 private String name;
25
26 /**
27 * @hibernate.property
28 */
29 private char sex;
30
31 /**
32 * @hibernate.property
33 */
34 private int age;
35 private UserManager manager = null;
36
37 /**
38 * @return Returns the manager.
39 */
40 public UserManager getManager() {
41 return manager;
42 }
43
44 /**
45 * @param manager The manager to set.
46 */
47 public void setManager(UserManager manager) {
48 this.manager = manager;
49 }
50
51 /**
52 * @return Returns the age.
53 */
54 public int getAge() {
55 return age;
56 }
57
58 /**
59 * @param age The age to set.
60 */
61 public void setAge(int age) {
62 this.age = age;
63 }
64
65 /**
66 * @return Returns the id.
67 */
68 public String getId() {
69 return id;
70 }
71
72 /**
73 * @param id The id to set.
74 */
75 public void setId(String id) {
76 this.id = id;
77 }
78
79 /**
80 * @return Returns the name.
81 */
82 public String getName() {
83 return name;
84 }
85
86 /**
87 * @param name The name to set.
88 */
89 public void setName(String name) {
90 this.name = name;
91 }
92
93 /**
94 * @return Returns the sex.
95 */
96 public char getSex() {
97 return sex;
98 }
99
100 /**
101 * @param sex The sex to set.
102 */
103 public void setSex(char sex) {
104 this.sex = sex;
105 }
106
107}
108
2
3import java.io.Serializable;
4
5/**
6 * @author martin.xus
7 * @hibernate.class table="t_user"
8 * @spring.bean name="user"
9 * @spring.property name="manager" ref="userManager"
10 */
11public class User implements Serializable {
12
13 /**
14 * @hibernate.id generator-class="uuid.hex"
15 * length="32"
16 * column="user_id"
17 */
18 private String id;
19
20 /**
21 * @hibernate.property column="user_name"
22 * length="80"
23 */
24 private String name;
25
26 /**
27 * @hibernate.property
28 */
29 private char sex;
30
31 /**
32 * @hibernate.property
33 */
34 private int age;
35 private UserManager manager = null;
36
37 /**
38 * @return Returns the manager.
39 */
40 public UserManager getManager() {
41 return manager;
42 }
43
44 /**
45 * @param manager The manager to set.
46 */
47 public void setManager(UserManager manager) {
48 this.manager = manager;
49 }
50
51 /**
52 * @return Returns the age.
53 */
54 public int getAge() {
55 return age;
56 }
57
58 /**
59 * @param age The age to set.
60 */
61 public void setAge(int age) {
62 this.age = age;
63 }
64
65 /**
66 * @return Returns the id.
67 */
68 public String getId() {
69 return id;
70 }
71
72 /**
73 * @param id The id to set.
74 */
75 public void setId(String id) {
76 this.id = id;
77 }
78
79 /**
80 * @return Returns the name.
81 */
82 public String getName() {
83 return name;
84 }
85
86 /**
87 * @param name The name to set.
88 */
89 public void setName(String name) {
90 this.name = name;
91 }
92
93 /**
94 * @return Returns the sex.
95 */
96 public char getSex() {
97 return sex;
98 }
99
100 /**
101 * @param sex The sex to set.
102 */
103 public void setSex(char sex) {
104 this.sex = sex;
105 }
106
107}
108
UserManager
1package com.martin.pdo;
2
3import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
4
5import java.util.List;
6
7/**
8 * @spring.bean name="userManager"
9&nb
2
3import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
4
5import java.util.List;
6
7/**
8 * @spring.bean name="userManager"
9&nb
相关推荐
Domain Object领域模型学习、设计、分析资料,错过别后悔。
Unsupervised Domain Adaption of Object Detectors A Survey.zip
Unsupervised Domain Adaption of Object Detectors A Survey.pdf
A Survey on Deep Domain Adaptation and Tiny Object Detection Challenges, Techniques and Datasets.pdf
A Survey on Deep Domain Adaptation and Tiny Object Detection Challenges, Techniques and Datasets.zip
目标检测,机器学习
Cross-Domain Weakly-Supervised Object Detectio.pdf
失血模型简单来说,就是domain object只有属性的getter/setter方法的纯数据类,所有的业务逻辑完全由business object来完成(又称TransactionScript),这种模型下的domain object被Martin Fowler称之为“贫血的domain...
深入理解ApplicationDomain和SecurityDomain
Connecting model and implementation more deeply * Sharpening key distinctions in a model * Managing the lifecycle of a domain object * Writing domain code that is safe to combine in elaborate ways * ...
我个人认为DDD最大的好处是将业务语义显现化,把原先晦涩难懂的业务算法逻辑,通过领域对象(Domain Object),统一语言(Ubiquitous Language)将领域概念清晰的显性化表达出来。相信我,这种表达带来的代码可读性...
Wavelet Transform Domain Filters
that go beyond image classification, such as face recognition, semantic segmentation and object detection. Fourth, some potential deficiencies of current methods and several future directions are ...
Domain adaptation is one of the most challenging tasks of modern data analytics. If the adaptation is done correctly, models built on a specific data representation become more robust when confronted ...
也许您已为此在收藏夹中准备了不少相关的查询网站、或是同时安装了多款 Whois 客户端等,而 Domain IP Locator 正是为提高您完成这些日常操作的效率而设计的一款免费软件,它集IP检索与域名归属查询于一身,且与许多...
crossdomain.xml用于unity3d生成的webplayer不能读取数据库的问题,用于unity3d生成的webplayer不能读取数据库的问题
详细介绍ApplicationDomain和SecurityDomain的原理,想对这方面的知识做深入研究的可以看下
By the end of the book, you will learn to use other design patterns such as DSLs to extend DDD with object-oriented design base, and then get an insight into how to select the right scenarios to ...
as object recognition, face recognition, activity analysis, concept clas- sification, and person detection. We then conclude by analyzing the challenges posed by the realm of “big visual data”, in ...