1.明天中秋啦,苦逼啊,自己一个人过啊,不过幸好有OA项目陪着也不孤单,继续做我的笔记,接着昨天的.
2.昨天笔记已经搭建好了SSH环境和SSH的整合,今天需要做的就是实体类的设计和分析,首先我们将资源结构分好建立一个config文件夹用来放置所有的配置文件,前文已经说过,注意需要放置在类路径下也就是直接在项目名右击建立sourcefolder,建立对应的jsp 存放页面,style存放样式,script存放脚本语言等等
3.根据项目的需求设计实体类,我这里是使用的starUml工具画的UML图,具体设计思路如下(实体设计很重要因为其中包括属性和各个表的之间的关联关系),我们是从系统管理做起的,其中包括用户管理,部门管理,岗位管理,具体设计如下图:
注意其中的关联关系很重要,因为等下在写hbm文件的时候,需要设置。
4.实体类设计好了以后,再根据图,写出domain对象代码如下,注意集合属性:
User
package com.icss.oa.domain; import java.util.HashSet; import java.util.Set; public class User { private long id; private Department department; private Set<Role> roles =new HashSet<Role>(); private String loginName; private String password; private String gender; private String phoneNumber; private String email; private String descrition; public long getId() { return id; } public void setId(long id) { this.id = id; } public Department getDepartment() { return department; } public void setDepartment(Department department) { this.department = department; } public Set<Role> getRoles() { return roles; } public void setRoles(Set<Role> roles) { this.roles = roles; } public String getLoginName() { return loginName; } public void setLoginName(String loginName) { this.loginName = loginName; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getGender() { return gender; } public void setGender(String gender) { this.gender = gender; } public String getPhoneNumber() { return phoneNumber; } public void setPhoneNumber(String phoneNumber) { this.phoneNumber = phoneNumber; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getDescrition() { return descrition; } public void setDescrition(String descrition) { this.descrition = descrition; } }Department
package com.icss.oa.domain; import java.util.HashSet; import java.util.Set; public class Department { private long id; private Set<User> users =new HashSet<User>(); private Department parent; private Set<Department> children; private String name; private String description; public long getId() { return id; } public void setId(long id) { this.id = id; } public Set<User> getUsers() { return users; } public void setUsers(Set<User> users) { this.users = users; } public Department getParent() { return parent; } public void setParent(Department parent) { this.parent = parent; } public Set<Department> getChildren() { return children; } public void setChildren(Set<Department> children) { this.children = children; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } }Role
package com.icss.oa.domain; import java.util.HashSet; import java.util.Set; public class Role { private long id; private String name; private String description; private Set<User> users = new HashSet<User>(); public long getId() { return id; } public void setId(long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDescription() { return description; } public void setDescription(String description) { this.description = description; } public Set<User> getUsers() { return users; } public void setUsers(Set<User> users) { this.users = users; } }
User.hbm,xml
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.icss.oa.domain"> <class name="User" table="t_user"> <id name="id" type="long"> <column name="user_id" /> <generator class="native" /> </id> <property name="loginName" type="java.lang.String"> <column name="user_name" /> </property> <property name="password" type="string"> <column name="user_password" /> </property> <property name="gender" type="string"> <column name="user_gender" /> </property> <property name="phoneNumber" type="string"> <column name="user_phoneNumber" /> </property> <property name="email" type="string"> <column name="user_email" /> </property> <property name="descrition" type="string"> <column name="user_descrition" /> </property> <!-- department属性,本类与Department的多对一 --> <many-to-one name="department" column="departmentId" class="Department"></many-to-one> <!-- roles属性,本类与Role多对多 --> <set name="roles" table="t_user_role"> <key column="userId"></key> <many-to-many class="Role" column="roleId"></many-to-many> </set> </class> </hibernate-mapping>
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.icss.oa.domain"> <class name="Department" table="t_department"> <id name="id" type="long"> <column name="department_id" /> <generator class="native" /> </id> <property name="name" type="java.lang.String"> <column name="department_name" /> </property> <!-- users属性,本类与User类的一对多 --> <set name="users"> <key column="departmentId"></key> <one-to-many class="User"/> </set> <!-- children属性,本类下级的1对多 --> <set name="children"> <key column="parentId"></key> <one-to-many class="Department"/> </set> <!-- parent属性,本类与上级的多对一 --> <many-to-one name="parent" class="Department" column="parentId"></many-to-one> </class> </hibernate-mapping>Role.hbm.xml
<?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.icss.oa.domain"> <class name="Role" table="t_role"> <id name="id" type="long"> <column name="role_id" /> <generator class="native" /> </id> <property name="name" type="java.lang.String"> <column name="role_name" /> </property> <property name="description" type="string"> <column name="role_description" /> </property> <!-- users属性,本类与User多对多 --> <set name="users" table="t_user_role"> <key column="roleId"></key> <many-to-many class="User" column="userId"></many-to-many> </set> </class> </hibernate-mapping>
7.明天做Action service dao 层的设计
原文地址:http://blog.csdn.net/dq3wrr/article/details/39121381