Guushuuse .NET
专注于ASP.NET 2.0、ASP.NET AJAX、Spring.NET、NHiberbate技术
博客园
首页
新随笔
联系
订阅
管理
41 Posts :: 0 Stories :: 89 Comments :: 18 Trackbacks
与我联系
发短消息
常用链接
我的随笔
我的空间
我的短信
我的评论
更多链接
我的参与
我的新闻
最新评论
我的标签
留言簿
(2)
给我留言
查看留言
我的标签
Spring.NET
(27)
ASP.NET AJAX
(26)
ASP.NET
(26)
NHibernate
(26)
随笔分类
ASP.NET&Spring.NET&NHibernate企业应用实践
ASP.NET&Spring.NET&NHibernate最佳实践(26)
NHibernate程序设计
Spring.NET程序设计
技巧集录(1)
技术手册(14)
随笔档案
2008年5月 (41)
.NET开源项目
AJAX Control Toolkit
log4net
NHibernate
Spring.NET
搜索
积分与排名
积分 - 24721
排名 - 1570
最新评论
1. re: ASP.NET&Spring.NET&NHibernate最佳实践(一)——目录
忽然发现楼主的这个是按照论文的格式写的,可以看做一篇不错的论文呢!
--Real_lsc
阅读排行榜
1. ASP.NET&Spring.NET&NHibernate最佳实践(八)——第4章权限子系统(1) (3052)
2. ASP.NET&Spring.NET&NHibernate最佳实践(二十六)——第4章权限子系统(19)权限子系统小结 (2635)
3. Agile Software Development(敏捷软件开发)(1979)
4. ASP.NET&Spring.NET&NHibernate最佳实践(四)——第3章人事子系统(1)(1975)
5. Spring.NET(1711)
评论排行榜
1. Agile Software Development(敏捷软件开发)(17)
2. ASP.NET&Spring.NET&NHibernate最佳实践(三)——第2章环境准备(11)
3. 如何把彩色网页快速变为灰色网页(10)
4. ASP.NET&Spring.NET&NHibernate最佳实践(二十六)——第4章权限子系统(19)权限子系统小结 (9)
5. ASP.NET&Spring.NET&NHibernate最佳实践(四)——第3章人事子系统(1)(8)
ASP.NET&Spring.NET&NHibernate最佳实践(四)——第3章人事子系统(1)
人事子系统分层结构为:领域模型层(DomainModel)——数据访问层(Dao)——服务层(Sevice)——表示层(Web),在Web页面中采用了ObjectDataSource作为GridView的数据源,并为此增加了一个帮助类。
在数据访问层中充分体现了Spring.NET和NHibernate的无缝集成,只要继承HibernateDaoSupport就能很便捷的使用NHibernate,而不需要很深入了解NHibernate。
3.1. 人事子系统领域模型层(DomainModel)
部门(Dept.cs)
using
System;
using
System.Collections.Generic;
using
System.Text;
namespace
Guushuuse.SalaryPrj.HR.DomainModel
{
/**/
///
<summary>
///
部门
///
</summary>
public
class
Dept
{
private
int
_id;
private
string
_code;
private
string
_name;
属性
#region
属性
/**/
///
<summary>
///
ID
///
</summary>
public
virtual
int
ID
{
get
{
return
_id; }
set
{ _id
=
value; }
}
/**/
///
<summary>
///
部门代码
///
</summary>
public
virtual
string
Code
{
get
{
return
_code; }
set
{ _code
=
value; }
}
/**/
///
<summary>
///
部门名称
///
</summary>
public
virtual
string
Name
{
get
{
return
_name; }
set
{ _name
=
value; }
}
#endregion
属性
构造函数
#region
构造函数
/**/
///
<summary>
///
///
</summary>
public
Dept()
{
this
._id
=
-
1
;
this
._code
=
String.Empty;
this
._name
=
String.Empty;
}
#endregion
构造函数
}
}
员工(Employee.cs)
using
System;
using
System.Collections.Generic;
using
System.Text;
namespace
Guushuuse.SalaryPrj.HR.DomainModel
{
/**/
///
<summary>
///
员工
///
</summary>
public
class
Employee
{
private
int
_id;
private
string
_code;
private
string
_name;
private
Dept _dept;
属性
#region
属性
/**/
///
<summary>
///
ID
///
</summary>
public
virtual
int
ID
{
get
{
return
_id; }
set
{ _id
=
value; }
}
/**/
///
<summary>
///
工号
///
</summary>
public
virtual
string
Code
{
get
{
return
_code; }
set
{ _code
=
value; }
}
/**/
///
<summary>
///
姓名
///
</summary>
public
virtual
string
Name
{
get
{
return
_name; }
set
{ _name
=
value; }
}
/**/
///
<summary>
///
部门
///
</summary>
public
virtual
Dept Dept
{
get
{
return
_dept; }
set
{ _dept
=
value; }
}
/**/
///
<summary>
///
部门ID
///
</summary>
public
virtual
int
DeptID
{
get
{
if
(_dept
!=
null
)
{
return
_dept.ID;
}
else
{
return
-
1
;
}
}
}
/**/
///
<summary>
///
部门名称
///
</summary>
public
virtual
string
DeptName
{
get
{
if
(_dept
!=
null
)
{
return
_dept.Name;
}
else
{
return
String.Empty;
}
}
}
#endregion
属性
构造函数
#region
构造函数
/**/
///
<summary>
///
///
</summary>
public
Employee()
{
this
._id
=
-
1
;
this
._code
=
String.Empty;
this
._name
=
String.Empty;
}
#endregion
构造函数
}
}
3.2. 人事子系统映射文件(HBM)
Dept.hbm.xml
<?
xml version="1.0" encoding="utf-8"
?>
<
hibernate-mapping
xmlns
="urn:nhibernate-mapping-2.2"
>
<
class
name
="Guushuuse.SalaryPrj.HR.DomainModel.Dept, Guushuuse.SalaryPrj.HR"
table
="t_depts"
>
<
id
name
="ID"
column
="dept_id"
type
="Int32"
unsaved-value
="-1"
>
<
generator
class
="identity"
/>
</
id
>
<
property
name
="Code"
column
="dept_code"
type
="String"
length
="255"
not-null
="true"
/>
<
property
name
="Name"
column
="dept_name"
type
="String"
length
="255"
not-null
="true"
/>
</
class
>
</
hibernate-mapping
>
Employee.hbm.xml
<?
xml version="1.0" encoding="utf-8"
?>
<
hibernate-mapping
xmlns
="urn:nhibernate-mapping-2.2"
>
<
class
name
="Guushuuse.SalaryPrj.HR.DomainModel.Employee, Guushuuse.SalaryPrj.HR"
table
="t_employees"
>
<
id
name
="ID"
column
="employee_id"
type
="Int32"
unsaved-value
="-1"
>
<
generator
class
="identity"
/>
</
id
>
<
property
name
="Code"
column
="employee_code"
type
="String"
length
="255"