Hibernate第五课.docx

上传人:b****6 文档编号:6326202 上传时间:2023-01-05 格式:DOCX 页数:81 大小:425.30KB
下载 相关 举报
Hibernate第五课.docx_第1页
第1页 / 共81页
Hibernate第五课.docx_第2页
第2页 / 共81页
Hibernate第五课.docx_第3页
第3页 / 共81页
Hibernate第五课.docx_第4页
第4页 / 共81页
Hibernate第五课.docx_第5页
第5页 / 共81页
点击查看更多>>
下载资源
资源描述

Hibernate第五课.docx

《Hibernate第五课.docx》由会员分享,可在线阅读,更多相关《Hibernate第五课.docx(81页珍藏版)》请在冰豆网上搜索。

Hibernate第五课.docx

Hibernate第五课

第五课员工管理系统的升级

一、使用Struts+Hibernate完成员工管理系统

二、建立数据库和表

createdatabaseempdb

go

useempdb

go

--部门表

createtabledep(

depidintidentityprimarykey,

depnamevarchar(50)unique

--职位表

createtablepositions(

pidintidentityprimarykey,

pnamevarchar(50)notnullunique

--福利表

createtablewelfare(

widintidentityprimarykey,

wnamevarchar(50)notnullunique

--员工表

createtableemp(

eidintidentityprimarykey,

enamevarchar(50),

sexvarchar(4),

addressvarchar(150),

birthdaydatetime,

depidintnotnullreferencesdep(depid),

pidintnotnullreferencespositions(pid),

photoimage

--员工福利表

createtableempwelfare(

ewidintidentityprimarykey,

eidintnotnullreferencesemp(eid),

widintnotnullreferenceswelfare(wid)

--薪资表

createtablesalary(

sidintidentityprimarykey,

smoneymoney,

eidintnotnulluniquereferencesemp(eid)

--插入基础数据

insertintodepvalues('技术部')

insertintodepvalues('财务部')

insertintodepvalues('市场部')

insertintodepvalues('行政部')

insertintodepvalues('人事部')

insertintodepvalues('研发部')

insertintopositionsvalues('软件工程师')

insertintopositionsvalues('系统设计师')

insertintopositionsvalues('财务专员')

insertintopositionsvalues('测试工程师')

insertintopositionsvalues('行政专员')

insertintopositionsvalues('人事专员')

insertintowelfarevalues('三金')

insertintowelfarevalues('交通补助')

insertintowelfarevalues('住房补助')

insertintowelfarevalues('取暖费')

insertintowelfarevalues('降温费')

insertintowelfarevalues('通讯费')

insertintowelfarevalues('午餐费')

关系图如下:

三、实现步骤

1、在当前工程引入struts和hibernate组件包

2、生成pojo类和dao类

生成的实体类如下所示:

(1)Dep.java

packagecom.po;

importjava.util.HashSet;

importjava.util.Set;

publicclassDepimplementsjava.io.Serializable{

//Fields

privateIntegerdepid;

privateStringdepname;

privateSetemps=newHashSet(0);

//Constructors

/**defaultconstructor*/

publicDep(){

}

/**fullconstructor*/

publicDep(Stringdepname,Setemps){

this.depname=depname;

this.emps=emps;

}

//Propertyaccessors

publicIntegergetDepid(){

returnthis.depid;

}

publicvoidsetDepid(Integerdepid){

this.depid=depid;

}

publicStringgetDepname(){

returnthis.depname;

}

publicvoidsetDepname(Stringdepname){

this.depname=depname;

}

publicSetgetEmps(){

returnthis.emps;

}

publicvoidsetEmps(Setemps){

this.emps=emps;

}

}

(2)Positions.java

packagecom.po;

importjava.util.HashSet;

importjava.util.Set;

publicclassPositionsimplementsjava.io.Serializable{

//Fields

privateIntegerpid;

privateStringpname;

privateSetemps=newHashSet(0);

//Constructors

/**defaultconstructor*/

publicPositions(){

}

/**minimalconstructor*/

publicPositions(Stringpname){

this.pname=pname;

}

/**fullconstructor*/

publicPositions(Stringpname,Setemps){

this.pname=pname;

this.emps=emps;

}

//Propertyaccessors

publicIntegergetPid(){

returnthis.pid;

}

publicvoidsetPid(Integerpid){

this.pid=pid;

}

publicStringgetPname(){

returnthis.pname;

}

publicvoidsetPname(Stringpname){

this.pname=pname;

}

publicSetgetEmps(){

returnthis.emps;

}

publicvoidsetEmps(Setemps){

this.emps=emps;

}

}

(3)Emp.java

packagecom.po;

importjava.util.*;

importjava.util.HashSet;

importjava.util.Set;

/**

*Empentity.@authorMyEclipsePersistenceTools

*/

publicclassEmpimplementsjava.io.Serializable{

//Fields

privateIntegereid;

privatePositionspositions=newPositions();

privateDepdep=newDep();

privateStringename;

privateStringsex="男";

privateStringaddress;

privateDatebirthday;

privatebyte[]photo;

privateSetempwelfares=newHashSet(0);

privateSetsalaries=newHashSet(0);

//Constructors

/**defaultconstructor*/

publicEmp(){

}

/**minimalconstructor*/

publicEmp(Positionspositions,Depdep){

this.positions=positions;

this.dep=dep;

}

/**fullconstructor*/

publicEmp(Positionspositions,Depdep,Stringename,Stringsex,

Stringaddress,Datebirthday,byte[]photo,Setempwelfares,

Setsalaries){

this.positions=positions;

this.dep=dep;

this.ename=ename;

this.sex=sex;

this.address=address;

this.birthday=birthday;

this.photo=photo;

this.empwelfares=empwelfares;

this.salaries=salaries;

}

//Propertyaccessors

publicIntegergetEid(){

returnthis.eid;

}

publicvoidsetEid(Integereid){

this.eid=eid;

}

publicPositionsgetPositions(){

returnthis.positions;

}

publicvoidsetPositions(Positionspositions){

this.positions=positions;

}

publicDepgetDep(){

returnthis.dep;

}

publicvoidsetDep(Depdep){

this.dep=dep;

}

publicStringgetEname(){

returnthis.ename;

}

publicvoidsetEname(Stringename){

this.ename=ename;

}

publicStringgetSex(){

returnthis.sex;

}

publicvoidsetSex(Stringsex){

this.sex=sex;

}

publicStringgetAddress(){

returnthis.address;

}

publicvoidsetAddress(Stringaddress){

this.address=address;

}

publicDategetBirthday(){

returnthis.birthday;

}

publicvoidsetBirthday(Datebirthday){

this.birthday=birthday;

}

publicbyte[]getPhoto(){

returnthis.photo;

}

publicvoidsetPhoto(byte[]photo){

this.photo=photo;

}

publicSetgetEmpwelfares(){

returnthis.empwelfares;

}

publicvoidsetEmpwelfares(Setempwelfares){

this.empwelfares=empwelfares;

}

publicSetgetSalaries(){

returnthis.salaries;

}

publicvoidsetSalaries(Setsalaries){

this.salaries=salaries;

}

}

(4)Empwelfare.java

packagecom.po;

/**

*Empwelfareentity.@authorMyEclipsePersistenceTools

*/

publicclassEmpwelfareimplementsjava.io.Serializable{

//Fields

privateIntegerewid;

privateEmpemp;

privateWelfarewelfare;

//Constructors

/**defaultconstructor*/

publicEmpwelfare(){

}

/**fullconstructor*/

publicEmpwelfare(Empemp,Welfarewelfare){

this.emp=emp;

this.welfare=welfare;

}

//Propertyaccessors

publicIntegergetEwid(){

returnthis.ewid;

}

publicvoidsetEwid(Integerewid){

this.ewid=ewid;

}

publicEmpgetEmp(){

returnthis.emp;

}

publicvoidsetEmp(Empemp){

this.emp=emp;

}

publicWelfaregetWelfare(){

returnthis.welfare;

}

publicvoidsetWelfare(Welfarewelfare){

this.welfare=welfare;

}

}

(5)Welfare.java

packagecom.po;

importjava.util.HashSet;

importjava.util.Set;

/**

*Welfareentity.@authorMyEclipsePersistenceTools

*/

publicclassWelfareimplementsjava.io.Serializable{

//Fields

privateIntegerwid;

privateStringwname;

privateSetempwelfares=newHashSet(0);

//Constructors

/**defaultconstructor*/

publicWelfare(){

}

/**minimalconstructor*/

publicWelfare(Stringwname){

this.wname=wname;

}

/**fullconstructor*/

publicWelfare(Stringwname,Setempwelfares){

this.wname=wname;

this.empwelfares=empwelfares;

}

//Propertyaccessors

publicIntegergetWid(){

returnthis.wid;

}

publicvoidsetWid(Integerwid){

this.wid=wid;

}

publicStringgetWname(){

returnthis.wname;

}

publicvoidsetWname(Stringwname){

this.wname=wname;

}

publicSetgetEmpwelfares(){

returnthis.empwelfares;

}

publicvoidsetEmpwelfares(Setempwelfares){

this.empwelfares=empwelfares;

}

}

(6)Salary.java

packagecom.po;

/**

*Salaryentity.@authorMyEclipsePersistenceTools

*/

publicclassSalaryimplementsjava.io.Serializable{

//Fields

privateIntegersid;

privateEmpemp;

privateDoublesmoney;

//Constructors

/**defaultconstructor*/

publicSalary(){

}

/**minimalconstructor*/

publicSalary(Empemp){

this.emp=emp;

}

/**fullconstructor*/

publicSalary(Empemp,Doublesmoney){

this.emp=emp;

this.smoney=smoney;

}

//Propertyaccessors

publicIntegergetSid(){

returnthis.sid;

}

publicvoidsetSid(Integersid){

this.sid=sid;

}

publicEmpgetEmp(){

returnthis.emp;

}

publicvoidsetEmp(Empemp){

this.emp=emp;

}

publicDoublegetSmoney(){

returnthis.smoney;

}

publicvoidsetSmoney(Doublesmoney){

this.smoney=smoney;

}

}

3、打开struts-config.xml文件,在设计视图建立ForemBean类和Action类,并设计访问流程。

EmpForm类设计如下:

/*

*GeneratedbyMyEclipseStruts

*Templatepath:

templates/java/JavaClass.vtl

*/

packagecom.zhhlk.struts.form;

importjavax.servlet.http.HttpServletRequest;

importorg.apache.struts.action.ActionErrors;

importorg.apache.struts.action.ActionForm;

importorg.apache.struts.action.ActionMapping;

importorg.apache.struts.upload.FormFile;

importcom.po.Emp;

/**

*MyEclipseStruts

*Creationdate:

05-03-2012

*

*XDocletdefinition:

*@struts.formname="empForm"

*/

publicclassEmpFormextendsActionForm{

/*

*Generatedfields

*/

/**birthdayproperty*/

privateStringbirthday;

/**widproperty*/

privateString[]wid;//用于获取页面显示的福利信息

/**upfileproperty*/

privateFormFileupfile;//文件上传的属性

/**salaryproperty*/

privateStringsalary;

/**empproperty*/

privateEmpemp=newEmp();

/*

*GeneratedMethods

*/

/**

*Methodvalidate

*@parammapping

*@paramrequest

*@returnActionErrors

*/

publicActionErrorsvalidate(ActionMappingmapping,

HttpServletRequestrequest){

//TODOAuto-generatedmethodstub

returnnull;

}

/**

*Methodreset

*@parammapping

*@paramrequest

*/

publicvoidreset(ActionMappingmapping,HttpServletRequestrequest){

//TODOAuto-generatedmethodstub

}

/**

*Returnsthebirthday.

*@returnString

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 表格模板 > 合同协议

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1