武汉纺织大学高级网站设计试验报告2

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

武汉纺织大学《高级网站设计》实验报告班级:姓名:实验时间:2014年5月7日指导教师:陈冈一、实验目的1.了解数据库连接池。2.掌握Spring应用。3.掌握Hibernate应用。二、实验内容1.创建一个基于SpringMVC的Web应用项目。2.实现项目的国际化处理。3.实现用户的登录、注册处理。4.编写一个小型留言板系统,利用Hibernate实现留言板处理。三、操作步骤1.cn.edu.wtu.cg.dao:Teacher类:packagecn.edu.wtu.cg.domain;publicclassTeacher{privateStringjobTitle;privateStringeno;privateStringename;privateStringpassword;publicStringgetEno(){returneno;}publicvoidsetEno(Stringeno){this.eno=eno;}publicStringgetEname(){returnename;}publicvoidsetEname(Stringename){this.ename=ename;}publicStringgetJobTitle(){returnjobTitle;}publicvoidsetJobTitle(StringjobTitle){this.jobTitle=jobTitle;}publicStringgetPassword(){returnpassword;}publicvoidsetPassword(Stringpassword){this.password=password;}}Student类:packagecn.edu.wtu.cg.domain;publicclassStudent{privateStringeno;privateStringemail;privateStringename;privateStringpassword;privateStringaddress;publicStringgetEname(){returnename;}publicvoidsetEname(Stringename){this.ename=ename;}publicStringgetEno(){returneno;}publicvoidsetEno(Stringeno){this.eno=eno;}publicStringgetEmail(){returnemail;}publicvoidsetEmail(Stringemail){this.email=email;}publicStringgetPassword(){returnpassword;}publicvoidsetPassword(Stringpassword){this.password=password;}publicStringgetAddress(){returnaddress;}publicvoidsetAddress(Stringaddress){this.address=address;}}Loginer类:packagecn.edu.wtu.cg.domain;publicclassLoginer{privateStringeno;privateStringpassword;privateStringCategory;publicStringgetEno(){returneno;}publicvoidsetEno(Stringeno){this.eno=eno;}publicStringgetPassword(){returnpassword;}publicvoidsetPassword(Stringpassword){this.password=password;}publicStringgetCategory(){returnCategory;}publicvoidsetCategory(Stringcategory){Category=category;}}BaseEnity类:packagecn.edu.wtu.cg.domain;publicclassBaseEntity{privateIntegerid;privateStringeno;privateStringename;privateStringpassword;publicIntegergetId(){returnid;}publicvoidsetId(Integerid){this.id=id;}publicStringgetEno(){returneno;}publicvoidsetEno(Stringeno){this.eno=eno;}publicStringgetEname(){returnename;}publicvoidsetEname(Stringename){this.ename=ename;}publicStringgetPassword(){returnpassword;}publicvoidsetPassword(Stringpassword){this.password=password;}}cn.edu.wtu.cg.dao:接口IUserDao:packagecn.edu.wtu.cg.dao;importjava.util.Collection;importorg.springframework.dao.DataAccessException;importcn.edu.wtu.cg.domain.Teacher;publicinterfaceIUserDaoT{publicTfindEntityByProperties(Stringeno,Stringpassword,Stringcategory)throwsDataAccessException;publicTfindEntityByEno(Stringeno,Stringcategory)throwsDataAccessException;publicvoidsaveEntity(Tentity)throwsDataAccessException;publicvoiddeleteEntity(Stringeno)throwsDataAccessException;publicCollectionTeacherfindEntityByDepartCode(StringdepartCode)throwsDataAccessException;}Ueserdao类:packagecn.edu.wtu.cg.dao;importjava.util.Collection;importjava.util.List;importjavax.sql.DataSource;importorg.springframework.beans.factory.annotation.Autowired;importorg.springframework.dao.DataAccessException;importorg.springframework.jdbc.core.BeanPropertyRowMapper;importorg.springframework.jdbc.core.JdbcTemplate;importorg.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;importorg.springframework.jdbc.core.simple.SimpleJdbcInsert;importorg.springframework.stereotype.Repository;importcn.edu.wtu.cg.domain.BaseEntity;importcn.edu.wtu.cg.domain.Student;importcn.edu.wtu.cg.domain.Teacher;@RepositorypublicclassUserDaoTimplementsIUserDaoT{privateJdbcTemplatejdbcTemplate;privateSimpleJdbcInsertinsertEntity;@Autowiredpublicvoidinit(DataSourcedataSource){jdbcTemplate=newJdbcTemplate(dataSource);insertEntity=newSimpleJdbcInsert(dataSource).usingGeneratedKeyColumns(id);}@SuppressWarnings(unchecked)@OverridepublicTfindEntityByProperties(Stringeno,Stringpassword,Stringcategory)throwsDataAccessException{try{Class?instance=null;Stringsql=null;if(category.equals(1)){instance=Teacher.class;sql=select*fromteacherwhereeno=?andpassword=?;}elseif(category.equals(2)){instance=Student.class;sql=select*fromstudentwhereeno=?andpassword=?;}return(T)jdbcTemplate.queryForObject(sql,newObject[]{eno,password},BeanPropertyRowMapper.newInstance(instance));}catch(Exceptione){}returnnull;}@SuppressWarnings(unchecked)@OverridepublicTfindEntityByEno(Stringeno,Stringcategory)throwsDataAccessException{Stringsql;Class?cls;if(category.equals(1)){sql=select*fromteacherwhereeno=?;cls=Teacher.class;}else{sql=select*fromstudentwhereeno=?;cls=Student.class;}List?list=jdbcTemplate.query(sql,BeanPropertyRowMapper.newInstance(cls),eno);if(list.size()==0)returnnull;return(T)list.get(0);}@OverridepublicvoidsaveEntity(Tregister)throwsDataAccessException{StringtableName=null;Stringsql=null;Stringeno;BaseEntityentity;if(registerinstanceofStudent){eno=((Student)register).getEno();entity=(BaseEntity)findEntityByEno(eno,2);tableName=student;sql=updatestudentsetpassword=?,ename=?,email=?,address=?whereeno=?;}else{eno=((Teacher)register).getEno();entity=(BaseEntity)findEntityByEno(eno,1);tableName=teacher;sql=updateteacherse

1 / 26
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功