【SSH】:基于Struts2+HIbernate3+Spring3实现员工管理系统之案例实现篇(上)

       案例:开发员工管理系统

       由于上一篇已经搭建了SSH开发环境,这一篇就来完成案例。过程不再赘述。

       创建的项目目录为:

       

       具体实现

       JSP页面

       1、index.jsp与frame.jsp及frame/*

       index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>登陆</title>
<link type="text/css" rel="stylesheet" href="<%=basePath %>css/reset.css">
<link type="text/css" rel="stylesheet" href="<%=basePath %>css/main.css">
</head>

<body>
	<div class="headerBar">
		<div class="logoBar login_logo">
			<div class="comWidth">
				<div class="logo fl">
					<a href="#"><img src="<%=basePath %>images/logo.jpg" alt="慕课网" /></a>
				</div>
				<h3 class="welcome_title">欢迎登陆</h3>
			</div>
		</div>
	</div>
	<s:form action="employee_login" method="post" namespace="/" theme="simple">
		<div class="loginBox">
			<h3>
			    <!-- 显示错误信息 -->
			    <s:actionerror />
			</h3>
			<div class="login_cont">
				<ul class="login">
					<li class="l_tit">用户名:</li>
					<li class="mb_10"><input type="text" name="username" class="login_input user_icon"></li>
					<li class="l_tit">密码:</li>
					<li class="mb_10"><input type="text" name="password" class="login_input user_icon"></li>
					<li><input type="submit" value="" class="login_btn"></li>
				</ul>
				
				<div class="login_partners">
					<p class="l_tit">使用合作方账号登陆网站</p>
					<ul class="login_list clearfix">
						<li><a href="#">QQ</a></li>
						<li><span>|</span></li>
						<li><a href="#">网易</a></li>
						<li><span>|</span></li>
						<li><a href="#">新浪微博</a></li>
						<li><span>|</span></li>
						<li><a href="#">腾讯微薄</a></li>
						<li><span>|</span></li>
						<li><a href="#">新浪微博</a></li>
						<li><span>|</span></li>
						<li><a href="#">腾讯微薄</a></li>
					</ul>
				</div>
			</div>

		</div>
	</s:form>
	<div class="hr_25"></div>
	<div class="footer">
		<p>
			<a href="#">慕课简介</a><i>|</i>
			<a href="#">慕课公告</a><i>|</i> 
			<a href="#">招纳贤士</a><i>|</i>
			<a href="#">联系我们</a><i>|</i>
			客服热线:400-675-1234
		</p>
		<p>Copyright &copy; 2006 - 2014
			慕课版权所有   
			京ICP备09037834号   
			京ICP证B1034-8373号   
			某市公安局XX分局备案编号:123456789123
		</p>
		<p class="web">
			<a href="#"><img src="<%=basePath %>images/webLogo.jpg" alt="logo"></a>
			<a href="#"><img src="<%=basePath %>images/webLogo.jpg" alt="logo"></a>
			<a href="#"><img src="<%=basePath %>images/webLogo.jpg" alt="logo"></a>
			<a href="#"><img src="<%=basePath %>images/webLogo.jpg" alt="logo"></a>
		</p>
	</div>
</body>
</html>

       frame.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>主页</title>
</head>

<frameset rows="80,*">
   <frame name="top" src="<%=basePath %>frame/top.jsp">
   <frameset cols="150,*" id="main">
      <frame src="<%=basePath %>frame/left.jsp"> 
      <frame name="right" src="<%=basePath %>frame/right.jsp">
   </frameset>
</frameset>
       frame/top.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
.div1 {
	margin-top: 50px;
	margin-left: 600px;
	font-size: 14px;
	color: white
}
</style>
</head>


<body bgcolor="#0099FF">
	<div class="div1">
		欢迎您:<s:property value="#session.exsitEmploy.ename" />
	</div>
</body>
</html>
       frame/left.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="<%=basePath %>css/dtree.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="<%=basePath %>js/dtree.js"></script>
</head>

<body bgColor="#DDF0FB" leftMargin="0" topMargin="0" marginwidth="0" marginheight="0">
	<table width="90%" border="0" cellspacing="1" cellpadding="2" align="center">
		<div class="dtree">		     
			<script type="text/javascript">
				d = new dTree('d');
				d.add('01', '-1', '员工管理系统');
				d.add('0101', '01', '人力资源部');
				d.add('010101', '0101', '部门管理', 'department_findAll.action','', 'right');
				d.add('010102', '0101', '员工管理', 'employee_findAll.action','','right');
				document.write(d);
			</script>
		</div>
	</table>
</body>
</html>

       frame/right.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>

<body>
	<div align="center">
		<table border="0" width="60%" cellspacing="0" cellpadding="0" id="table1">
			<tr>
				<td height="93"></td>
			</tr>
			<tr>
				<td>
				   <img src="<%=basePath %>images/bg.jpg" style="background-repeat: no-repeat" width="1500px" height="600px">
			    </td>
			</tr>
		</table>
	</div>
</body>
</html>

       2、jsp/department/*

       listDepartment.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
.table1 {
	border: 1px solid #ddd;
	width: 900px;
}

thead {
	background-color: lightblue;
}
</style>
</head>
<body>     
	<table border="0" width="900px">
		<tr>
			<td align="center" style="font-size: 24px; color: #666">部门管理</td>
		</tr>
		<tr>
			<td align="right">
			    <a href="department_saveUI.action">添加</a>
			</td>
		</tr>
	</table>
	<br/>
	<table cellspacing="0" border="1" class="table1">
		<thead>
			<tr>
				<th width="300">部门名称</th>
				<th width="300">编辑</th>
				<th width="300">删除</th>
			</tr>
		</thead>
		<tbody>
			<s:iterator value="list" var="d">
				<tr>
					<td align="center"><s:property value="#d.dname" /></td>
					<td align="center">
					   <a href="department_editById.action?did=<s:property value="#d.did"/>">
					      <img src="<%=basePath %>images/编辑.png" />
					   </a>
					</td>
					<td align="center">
					    <a href="department_delete.action?did=<s:property value="#d.did"/>">
					       <img src="<%=basePath %>images/trash.gif" />
					    </a>
				    </td>
				</tr>
			</s:iterator>
		</tbody>
	</table>
	<br/>
	<table border="0" cellspacing="0" cellpadding="0" width="900px">
		<tr>
			<td align="right">
			<span>
			     第<s:property value="currentPage" />/<s:property value="pageSize" />页
			</span>
			   
			<span>
			    总记录数:<s:property value="totalSize" />  
			    每页显示:<s:property value="pageCount" /></span>   
			<span>
			   <s:if test="currentPage != 1">
					<a href="department_findAll.action?currentPage=1">[首页]</a>  
                    <a href="department_findAll.action?currentPage=<s:property value="currentPage-1"/>">[上一页]</a>  
               </s:if> 
               <s:if test="currentPage != pageSize">
					<a href="department_findAll.action?currentPage=<s:property value="currentPage+1"/>">[下一页]</a>  
                    <a href="department_findAll.action?currentPage=<s:property value="pageSize"/>">[尾页]</a>  
               </s:if> 
            </span>
            </td>
		</tr>
	</table>
</body>
</html>

       addDepartment.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>添加部门</title>
</head>

<body>
	<table border="0" width="600px">
		<tr>
			<td align="center" style="font-size: 24px; color: #666">部门添加</td>
		</tr>
		<tr>
			<td align="right">
			     <a href="javascript:document.getElementById('saveForm').submit()">保存</a>
			        
			     <a href="javascript:history.go(-1)">退回 </a>
			</td>
		</tr>
	</table>
	<br/>
	<br/>
	<!-- action对应一个action标签,id对应提交时的对应关系 -->
	<s:form id="saveForm" action="department_save" method="post" namespace="/" theme="simple">
		<table style="font-size:16px"width="600px">
			<tr>
				<td width="30%" align="right">部门名称:</td>
				<td><s:textfield name="dname" /></td>
			</tr>
			<tr>
				<td width="30%" align="right">部门介绍:</td>
				<td><s:textarea rows="5" cols="50" name="ddesc"></s:textarea></td>
			</tr>
		</table>
	</s:form>
</body>
</html>

       editDepartment.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>

<body>
	<table border="0" width="600px">
		<tr>
			<td align="center" style="font-size: 24px; color: #666">编辑部门</td>
		</tr>
		<tr>
			<td align="right">
			    <a href="javascript:document.getElementById('saveForm').submit()">保存</a>
				   
				<a href="javascript:history.go(-1)">退回 </a>
		    </td>
		</tr>
	</table>
	<br/>
	<br/>
	<!-- action对应一个action标签,id对应提交时的对应关系 -->
	<s:form id="saveForm" action="department_update" method="post" namespace="/" theme="simple">
		<!-- 隐藏域,指明修改的是哪个部门 -->
		<s:hidden name="did" value="%{model.did}"></s:hidden>
		<table style="font-size:16px" width="600px">
			<tr>
				<td width="30%" align="right">部门名称:</td>
				<td><s:textfield name="dname" value="%{model.dname}" /></td>
			</tr>
			<tr>
				<td width="30%" align="right">部门介绍:</td>
				<td></td>
			</tr>
			<tr>
				<td width="30%" align="right"></td>
				<td><s:textarea rows="5" cols="50" name="ddesc" value="%{model.ddesc}"></s:textarea></td>
			</tr>
		</table>
	</s:form>
</body>
</html> 

       3、jsp/employee/*

       listEpartment.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
.table1 {
	border: 1px solid #ddd;
	width: 900px;
}

thead {
	background-color: lightblue;
}
</style>
</head>
<body>
	<table border="0" width="900px">
		<tr>
			<td align="center" style="font-size: 24px; color: #666">员工管理</td>
		</tr>
		<tr>
			<td align="right">
			      <a href="employee_saveUI.action">添加</a>
			</td>
		</tr>
	</table>
	<br />
	<table cellspacing="0" border="1" class="table1">
		<thead>
			<tr>
				<th width="300">员工编号</th>
				<th width="300">员工姓名</th>
				<th width="100">性别</th>
				<th width="500">出生日期</th>
				<th width="500">入职时间</th>
				<th width="300">所在部门</th>
				<th width="300">编辑</th>
				<th width="300">删除</th>
			</tr>
		</thead>
		<tbody>
			<s:iterator value="list" var="e">
				<tr>
					<td align="center"><s:property value="#e.eno" /></td>
					<td align="center"><s:property value="#e.ename" /></td>
					<td align="center"><s:property value="#e.sex" /></td>
					<td align="center"><s:date format="yyyy-MM-dd" name="#e.birthday" /></td>
					<td align="center"><s:date name="#e.joinDay" format="yyyy-MM-dd" /></td>
					<td align="center"><s:property value="#e.department.dname" /></td>
					<td align="center">
					    <a href="employee_edit.action?eid=<s:property value="#e.eid"/>">
					       <img src="<%=basePath %>images/编辑.png" />
					    </a>
					</td>
					<td align="center">
					    <a href="employee_delete.action?eid=<s:property value="#e.eid"/>">
					       <img src="<%=basePath %>images/trash.gif" />
					    </a>
					</td>
				</tr>
			</s:iterator>
		</tbody>
	</table>
	<br/>
	<table border="0" cellspacing="0" cellpadding="0" width="900px">
		<tr>
			<td align="right">
			<span>
			     第<s:property value="currentPage" />/<s:property value="pageSize" />页
			</span>
			   
			<span>
			    总记录数:<s:property value="totalSize" />  
			    每页显示:<s:property value="pageCount" /></span>   
			<span>
			   <s:if test="currentPage != 1">
					<a href="employee_findAll.action?currentPage=1">[首页]</a>  
                    <a href="employee_findAll.action?currentPage=<s:property value="currentPage-1"/>">[上一页]</a>  
               </s:if> 
               <s:if test="currentPage != pageSize">
					<a href="employee_findAll.action?currentPage=<s:property value="currentPage+1"/>">[下一页]</a>  
                    <a href="employee_findAll.action?currentPage=<s:property value="pageSize"/>">[尾页]</a>  
               </s:if> 
            </span>
            </td>
		</tr>
	</table>
</body>
</html>

       addEmployee.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>

<body>
	<table border="0" width="600px">
		<tr>
			<td align="center" style="font-size: 24px; color: #666">员工添加</td>
		</tr>
		<tr>
			<td align="right">
			    <a href="javascript:document.getElementById('saveForm').submit()">保存</a>
				   
				<a href="javascript:history.go(-1)">退回 </a>
		   </td>
		</tr>
	</table>
	<br/>
	<br/>
	<!-- action对应一个action标签,id对应提交时的对应关系 -->
	<s:form id="saveForm" action="employee_save" method="post" namespace="/" theme="simple">
		<table style="font-size:16px">
			<tr>
				<td align="right">员工姓名:</td>
				<td><s:textfield name="ename" /></td>
				<td align="right">性别:</td>
				<td><s:radio list="{'男','女'}" name="sex" /></td>
			</tr>
			<tr>
				<td align="right">出生日期:</td>
				<td align="right"><s:textfield name="birthday" /></td>
				<td align="right">入职日期:</td>
				<td><s:textfield name="joinDay" /></td>
			</tr>
			<tr>
				<td align="right">用户名:</td>
				<td><s:textfield name="username" /></td>
				<td align="right">密码:</td>
				<td><s:password name="password" /></td>
			</tr>
			<tr>
				<td align="right">编号:</td>
				<td><s:textfield name="eno" /></td>
				<td align="right">部门:</td>
				<td><s:select name="department.did" list="list" listKey="did" listValue="dname" headerKey="0" headerValue="--请选择--" /></td>
			</tr>
		</table>
	</s:form>
</body>
</html> 

       editEmployee.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>

<body>
	<table border="0" width="600px">
		<tr>
			<td align="center" style="font-size: 24px; color: #666">员工修改</td>
		</tr>
		<tr>
			<td align="right">
			    <a href="javascript:document.getElementById('saveForm').submit()">保存</a>
				   
				<a href="javascript:history.go(-1)">退回 </a>
		    </td>
		</tr>
	</table>
	<br/>
	<br/>
	<!-- action对应一个action标签,id对应提交时的对应关系 -->
	<s:form id="saveForm" action="employee_update" method="post" namespace="/" theme="simple">
		<s:hidden name="eid" value="%{model.eid}"></s:hidden>
		<table style="font-size: :16px">
			<tr>
				<td align="right">员工姓名:</td>
				<td><s:textfield value="%{model.ename}" name="ename" /></td>
				<td align="right">性别:</td>
				<td><s:radio list="{'男','女'}" value="%{model.sex}" name="sex" /></td>
			</tr>
			<tr>
				<td align="right">出生日期:</td>
				<td><input type="text" name="birthday" value="<s:date name="model.birthday" format="yyyy-MM-dd"/>" /></td>
				<td align="right">入职日期:</td>
				<td><input type="text" name="joinDay" value="<s:date name="model.joinDay" format="yyyy-MM-dd"/>" /></td>
			</tr>
			<tr>
				<td align="right">用户名:</td>
				<td><s:textfield value="%{model.username}" name="username" /></td>
				<td align="right">密码:</td>
				<td><s:password value="%{model.password}" name="password" showPassword="true"/></td>
			</tr>
			<tr>
				<td align="right">编号:</td>
				<td><s:textfield value="%{model.eno}" name="eno" /></td>
				<td align="right">部门:</td>
				<td>
				    <s:select name="department.did" headerKey="0" value="%{model.department.did}" headerValue="--请选择--" list="list" listKey="did" listValue="dname" />
				</td>
			</tr>
		</table>
	</s:form>
</body>
</html> 

       实体类和对象关系映射文件

       Depaerment实体类

package com.employee.domain;

import java.util.HashSet;
import java.util.Set;

/**
 * 部门实体类
 * @author Administrator
 * @date 2016年12月24日
 */
public class Department {
	private Integer did;
	private String dname;
	private String ddesc;
	//部门员工的集合
	private Set<Employee> employee = new HashSet<Employee>();
	
	public Integer getDid() {
		return did;
	}
	
	public void setDid(Integer did) {
		this.did = did;
	}
	
	public String getDname() {
		return dname;
	}
	
	public void setDname(String dname) {
		this.dname = dname;
	}
	
	public String getDdesc() {
		return ddesc;
	}
	
	public void setDdesc(String ddesc) {
		this.ddesc = ddesc;
	}
	
	public Set<Employee> getEmployee() {
		return employee;
	}
	
	public void setEmployee(Set<Employee> employee) {
		this.employee = employee;
	}

}

       Department.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC 
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
	<class name="com.employee.domain.Department" table="department">
		<id name="did" column="did">
			<generator class="native"></generator>
		</id>
		
		<property name="dname" column="dname" length="20"></property>
		<property name="ddesc" column="ddesc" length="100"></property>
		
		<!-- 一对多关联映射 -->
		<set name="employee" cascade="all" inverse="true">
			<key column="dno" />
			<one-to-many class="com.employee.domain.Employee"/>
		</set>
		
	</class>
</hibernate-mapping>


       Employee实体类

package com.employee.domain;

import java.util.Date;

/**
 * 员工实体
 * @author Administrator
 * @date 2016年12月24日
 */
public class Employee {
	private Integer eid;
	private String ename;
	private String sex;
	private Date birthday;
	private Date joinDay;
	private String eno;
	private String username;
	private String password;
	//员工的所属部门
	private Department department;
	
	public Integer getEid() {
		return eid;
	}
	
	public void setEid(Integer eid) {
		this.eid = eid;
	}
	
	public String getEname() {
		return ename;
	}
	
	public void setEname(String ename) {
		this.ename = ename;
	}
	
	public String getSex() {
		return sex;
	}
	
	public void setSex(String sex) {
		this.sex = sex;
	}
	
	public Date getBirthday() {
		return birthday;
	}
	
	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}
	
	public Date getJoinDay() {
		return joinDay;
	}
	
	public void setJoinDay(Date joinDay) {
		this.joinDay = joinDay;
	}
	public String getEno() {
		return eno;
	}
	
	public void setEno(String eno) {
		this.eno = eno;
	}
	
	public String getUsername() {
		return username;
	}
	
	public void setUsername(String username) {
		this.username = username;
	}
	
	public String getPassword() {
		return password;
	}
	
	public void setPassword(String password) {
		this.password = password;
	}
	
	public Department getDepartment() {
		return department;
	}
	
	public void setDepartment(Department department) {
		this.department = department;
	}
	
}
       Employee.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC 
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    
<hibernate-mapping>
	<class name="com.employee.domain.Employee" table="employee">
		<id name="eid" column="eid">
			<generator class="native" />
		</id>
		
		<property name="ename" column="ename" length="20"/>
		<property name="sex" column="sex" length="10" />
		<property name="birthday" column="birthday" type="date" />
		<property name="joinDay" column="joinDay" type="date" />
		<property name="eno" column="eno" length="20" />
		<property name="username" column="username" length="20" />
		<property name="password" column="password" length="20" />
		
		<!-- 多对一关联映射 -->
		<many-to-one name="department" class="com.employee.domain.Department" cascade="save-update">
		     <column name="dno" />
		</many-to-one>
	
	</class>
</hibernate-mapping>

       PageBean实现类

package com.employee.domain;

import java.util.List;

/**
 * 分页Bean
 * @author Administrator
 * @date 2016年12月24日
 * @param <T>
 */
public class PageBean<T>{
	private Integer currentPage;//当前页数
	private Integer pageCount;//每页显示记录数
	private Integer pageSize;//总页数
	private Integer totalSize;//总记录数
	private List<T> list;     //每页显示的数据
	
	public Integer getCurrentPage() {
		return currentPage;
	}
	
	public void setCurrentPage(Integer currentPage) {
		this.currentPage = currentPage;
	}
	
	public Integer getPageCount() {
		return pageCount;
	}
	
	public void setPageCount(Integer pageCount) {
		this.pageCount = pageCount;
	}
	
	public Integer getPageSize() {
		return pageSize;
	}
	
	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}
	
	public Integer getTotalSize() {
		return totalSize;
	}
	
	public void setTotalSize(Integer totalSize) {
		this.totalSize = totalSize;
	}
	
	public List<T> getList() {
		return list;
	}
	
	public void setList(List<T> list) {
		this.list = list;
	}
	
}

       下一篇就是三层的实现了。


       


评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值