Hibernate Struts2 学生选课系统

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

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

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

资源描述

HibernateStruts2——HibernateStruts2HibernateORMHibernateStruts21.WebSVNcheckoutMyEclipseJavaEnterprisePackageExplorerimport“CheckoutProjectsfromSVN“CreateanewrepositorylocationURL(6)×XMChar(8)×XBbit×10CSSJdatetimeZY_IDIDint×ZXFintBZVarchar(200)ZPmediumblobdlbidint×1xhchar(6)×,xsbxhklchar(20)×zybidIDint×1zymchar(12)×rsint0fdychar(8)kcbkchChar3kcmChar12kxxqsmallint1-8xsint0xfint0xs_kcbxhchar(6)kchchar(3)3MyEclipseSQLServer1)“MyEclipseDatabaseExplorerMySQLMyEclipseWindowOpenPerspectiveMyEclipseDatabaseExplorerMyEclipseDatabase4.2NewDrivertemplateMySQLConnector/JDrivernamecom.mysql.jdbc.DriverConnectionURLjdbc:mysql://localhost:3306/javaeejavaeeUsernamerootPasswordrootJDBCprojectWebRoot\WEB-INF\lib2)MyEclipseDatabaseMyConn“Openconnection…”“MyConn”4.HibernateStruts_HibernateMyEclipseAddHibernateCapabilites4.5HibernateNextHibernatehibernate.cfg.xmlsrcHibernateNextHibernateMyConnDBDriver“MyConnNextHibernateSessionSessionFactorySessionFactoryFinishHibernate5.JavaMyEclispse“org.modelJavaPOJOMyEclipseDatabaseExplorerMyConnXSCJTABLEHibernateReverseEngineeringHibernateReverseEngineeringJavaJavaNextXsb.javapackageorg.model;importjava.util.Date;importjava.util.HashSet;importjava.util.Set;publicclassXsbimplementsjava.io.Serializable{privateStringxh;privateZybzyb;privateStringxm;privateBytexb;privateDatecssj;privateIntegerzxf;privateStringbz;privatebyte[]zp;privateSetkcs=newHashSet();//getset}Xsb.hbm.xml?xmlversion=1.0encoding=utf-8?!DOCTYPEhibernate-mappingPUBLIC-//Hibernate/HibernateMappingDTD3.0//EN=org.model.Xsbtable=XSBcatalog=XSCJidname=xhtype=java.lang.Stringcolumnname=XHlength=6/generatorclass=assigned//idmany-to-onename=zybclass=org.model.Zybfetch=selectcascade=alllazy=falsecolumnname=ZY_ID//many-to-onepropertyname=xmtype=java.lang.Stringcolumnname=XMlength=50//propertypropertyname=xbtype=java.lang.Bytecolumnname=XB//propertypropertyname=cssjtype=java.util.Datecolumnname=CSSJlength=23//propertypropertyname=zxftype=java.lang.Integercolumnname=ZXF//propertypropertyname=bztype=java.lang.Stringcolumnname=BZlength=500//propertypropertyname=zpcolumnname=ZP//propertysetname=kcstable=XS_KCBlazy=falsecascade=save-updatekeycolumn=XH/keymany-to-manyclass=org.model.Kcbcolumn=KCH/many-to-many/set/class/hibernate-mappingKcb.javapackageorg.model;importjava.util.HashSet;importjava.util.Set;publicclassKcbimplementsjava.io.Serializable{privateStringkch;privateStringkcm;privateShortkxxq;privateintxs;privateintxf;privateSetxss=newHashSet();//setget}Kcb.hbm.xml?xmlversion=1.0encoding=utf-8?!DOCTYPEhibernate-mappingPUBLIC-//Hibernate/HibernateMappingDTD3.0//EN=org.model.Kcbtable=KCBcatalog=XSCJidname=kchtype=java.lang.Stringcolumnname=KCHlength=4/generatorclass=assigned//idpropertyname=kcmtype=java.lang.Stringcolumnname=KCMlength=16//propertypropertyname=kxxqtype=java.lang.Shortcolumnname=KXXQ//propertypropertyname=xstype=java.lang.Integercolumnname=XS//propertypropertyname=xftype=java.lang.Integercolumnname=XF//propertysetname=xsstable=XS_KCBlazy=falsekeycolumn=KCH/keymany-to-manyclass=org.model.Xsbcolumn=XH/many-to-many/set/class/hibernate-mapping6.DaoDaopackageorg.daoorg.dao.impDlDao.javapackageorg.dao;importorg.model.Dlb;publicinterfaceDlDao{//publicDlbvalidate(Stringxh,Stringkl);}DlDaoImp.javapackageorg.dao.imp;importorg.dao.DlDao;importorg.hibernate.Query;importorg.hibernate.Session;importorg.hibernate.Transaction;importorg.model.Dlb;publicclassDlDaoImpimplementsDlDao{publicDlbvalidate(Stringxh,Stringkl){try{Sessionsession=org.util.HibernateSessionFactory.getSession();Transactionts=session.beginTransaction();Queryquery=session.createQuery(fromDlbwherexh=?andkl=?);query.setParameter(0,xh);query.setParameter(1,kl);query.setMaxResults(1);Dlbdlb=(Dlb)query.uniqueResult();if(dlb!=null){returndlb;}else{returnnull;}}catch(Exceptione){e.printStackTrace();returnnull;}}}DaoKcDao.javapackageorg.dao;importjava.util.List;importorg.model.Kcb;publicinterfaceKcDao{publicKcbgetOneKc(Stringkch);publicListgetAll();}KcDaoImp.javapackageorg.dao.imp;importjava.util.List;importorg.dao.KcDao;importorg.hibernate.Query;importorg.hibernate.Session;importorg.hibernate.Transaction;importorg.model.Kcb;publicclassKcDaoImpimplementsKcDao{publicKcbgetOneKc(Stringkch){try{Sessionsession=org.util.HibernateSessionFactory.getSession();Transactionts=session.beginTransaction();Queryquery=session.createQuery(fromKcbwherekch=?);query.setParameter(0,kch);query.setMaxResults(1);Kcbkc=(Kcb)query.uniqueResult();ts.commit();session.clear();returnkc;}catch(Exceptione){e.printStackTrace();returnnull;}}publicListgetAll(){try{Sessionsession=org.util.HibernateSessionF

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

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

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

×
保存成功