搭建SSH三大框架WEB项目过程(Struts2.3+Hibernate4.3+Spring4.1)
ÎÒÒÔÎÒ×öµÄÒ»¸öÀý×ÓÀ´ËµÃ÷¿ò¼ÜµÄ´î½¨¹ý³Ì ^V^£¡
ÏîÄ¿½á¹¹Èçͼ£º
action£º´æ·ÅActionÀ࣬Ҳ¾ÍÊÇ¿ØÖÆÀà
dao£ºDAOÊý¾Ý¿â²Ù×÷
po£ºPOJOÀ࣬Ҳ¾ÍÊdz־û¯Àà
service£º´æ·ÅServiceÀà
daoÀàÔÚServiceÀàÀïµ÷Óã¬È»ºóServiceÀàÔÙµ½actionÀàÀïµ÷ÓÃ
´î½¨¹ý³Ì
ÎÒÃÇÏÈҪ׼±¸jar¼Û°ü£¬Õâ¸ö¿ÉÒÔÈ¥¹ÙÍøÏÂÔØ
ÏÂÃæÊÇÎÒ×¼±¸µÄ¿ª·¢jar¼Û°ü
È»ºóÎÒΪÁËÌá¸ß°²È«ÐÔ£¬ÎÒ½«ËùÓеÄJSPÒ³Ãæ·ÅÔÚÁËWEB-INFÏÂÃæ
È»ºóÅäÖÃSSHµÄÅäÖÃÎļþ
SpringµÄÅäÖÃÎļþ´úÂ룺
[html] view plain copy print?
-
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd"> <!-- Spring¿ò¼ÜÅäÖÃÎļþ --> <!-- ÊôÐÔ×¢ÈëÅäÖà --> <context:annotation-config/> <!-- ʵÏÖÊý¾Ý¿âÅäÖà --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"></property> <property name="url" value="jdbc:mysql://localhost:3306/db_sgdata?useUnicode=true&characterEncoding=UTF-8"></property> <property name="username" value="root"></property> <property name="password" value="111"></property> <property name="maxActive" value="100"></property> <property name="maxIdle" value="60"></property> <property name="maxWait" value="10000"></property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"></property> <property name="configLocation" value="classpath:hibernate.cfg.xml"></property> </bean> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate4.HibernateTemplate"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- ¿ªÆôSpring¿ò¼ÜµÄÊÂÎñ¹ÜÀí £¬¿ªÆôÖ®ºó@Transaction¾Í¿ÉÒÔÓÃÁË --> <tx:annotation-driven transaction-manager="txManager"/> <!-- ʵÏÖ½ÌʦÐÅÏ¢¹ÜÀíÐèÒªÅäÖõÄBean --> <bean id="teacherDao" class="com.sgdata.dao.impl.TeacherDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="teacherService" class="com.sgdata.service.impl.TeacherServiceBean"> </bean> <!--scopeĬÈϲÉÓõÄÊǵ¥Àýģʽ£¬scope="prototype" ¿ÉÒÔ±£Ö¤ µ±ÓÐÇëÇóµÄʱºò¶¼´´½¨Ò»¸öAction¶ÔÏ󣬱£Ö¤StrutsµÄActionḬ̈߳²È« --> <bean id="teacherAction" class="com.sgdata.action.TeacherInfoManagerAction" scope="prototype"></bean> <bean id="loginCheckAction" class="com.sgdata.action.LoginCheckAction" scope="prototype"></bean> <!-- ʵÏÖѧÉúÐÅÏ¢¹ÜÀíÐèÒªÅäÖõÄBean --> <bean id="studentDao" class="com.sgdata.dao.impl.StudentDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="studentService" class="com.sgdata.service.impl.StudentServiceBean"></bean> <bean id="studentAction" class="com.sgdata.action.StudentInfoManagerAction" scope="prototype"></bean> <!-- ʵÏֿγÌÐÅÏ¢¹ÜÀíÐèÒªÅäÖõÄBean --> <bean id="courseDao" class="com.sgdata.dao.impl.CourseDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="courseService" class="com.sgdata.service.impl.CourseServiceBean"></bean> <bean id="courseAction" class="com.sgdata.action.CourseInfoManagerAction" scope="prototype"></bean> <!-- ʵÏÖ±ÈÈüÐÅÏ¢¹ÜÀíÐèÒªÅäÖõÄBean --> <bean id="matchDao" class="com.sgdata.dao.impl.MatchDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="matchService" class="com.sgdata.service.impl.MatchServiceBean"></bean> <bean id="matchAction" class="com.sgdata.action.MatchInfoManagerAction" scope="prototype"></bean> </beans>
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd"> <!-- Spring¿ò¼ÜÅäÖÃÎļþ --> <!-- ÊôÐÔ×¢ÈëÅäÖà --> <context:annotation-config/> <!-- ʵÏÖÊý¾Ý¿âÅäÖà --> <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver"></property> <property name="url" value="jdbc:mysql://localhost:3306/db_sgdata?useUnicode=true&characterEncoding=UTF-8"></property> <property name="username" value="root"></property> <property name="password" value="111"></property> <property name="maxActive" value="100"></property> <property name="maxIdle" value="60"></property> <property name="maxWait" value="10000"></property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> <property name="dataSource" ref="dataSource"></property> <property name="configLocation" value="classpath:hibernate.cfg.xml"></property> </bean> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate4.HibernateTemplate"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <!-- ¿ªÆôSpring¿ò¼ÜµÄÊÂÎñ¹ÜÀí £¬¿ªÆôÖ®ºó@Transaction¾Í¿ÉÒÔÓÃÁË --> <tx:annotation-driven transaction-manager="txManager"/> <!-- ʵÏÖ½ÌʦÐÅÏ¢¹ÜÀíÐèÒªÅäÖõÄBean --> <bean id="teacherDao" class="com.sgdata.dao.impl.TeacherDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="teacherService" class="com.sgdata.service.impl.TeacherServiceBean"> </bean> <!--scopeĬÈϲÉÓõÄÊǵ¥Àýģʽ£¬scope="prototype" ¿ÉÒÔ±£Ö¤ µ±ÓÐÇëÇóµÄʱºò¶¼´´½¨Ò»¸öAction¶ÔÏ󣬱£Ö¤StrutsµÄActionḬ̈߳²È« --> <bean id="teacherAction" class="com.sgdata.action.TeacherInfoManagerAction" scope="prototype"></bean> <bean id="loginCheckAction" class="com.sgdata.action.LoginCheckAction" scope="prototype"></bean> <!-- ʵÏÖѧÉúÐÅÏ¢¹ÜÀíÐèÒªÅäÖõÄBean --> <bean id="studentDao" class="com.sgdata.dao.impl.StudentDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="studentService" class="com.sgdata.service.impl.StudentServiceBean"></bean> <bean id="studentAction" class="com.sgdata.action.StudentInfoManagerAction" scope="prototype"></bean> <!-- ʵÏֿγÌÐÅÏ¢¹ÜÀíÐèÒªÅäÖõÄBean --> <bean id="courseDao" class="com.sgdata.dao.impl.CourseDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="courseService" class="com.sgdata.service.impl.CourseServiceBean"></bean> <bean id="courseAction" class="com.sgdata.action.CourseInfoManagerAction" scope="prototype"></bean> <!-- ʵÏÖ±ÈÈüÐÅÏ¢¹ÜÀíÐèÒªÅäÖõÄBean --> <bean id="matchDao" class="com.sgdata.dao.impl.MatchDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="matchService" class="com.sgdata.service.impl.MatchServiceBean"></bean> <bean id="matchAction" class="com.sgdata.action.MatchInfoManagerAction" scope="prototype"></bean> </beans>
Struts2µÄÅäÖÃÎļþ´úÂ룺
[html] view plain copy print?
-
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <!-- Struts2¿ò¼ÜÅäÖÃÎļþ --> <struts> <!-- ÅäÖÃstruts2¿ÉÒÔÊÜÀíµÄÇëÇóÀ©Õ¹Ãû --> <constant name="struts.action.extension" value="action,do,"></constant> <!-- struts2µÄpackage¶ÔÓ¦ÓÚÏîÄ¿µÄÄ£¿é --> <package name="action" extends="struts-default" namespace="/"> <!-- ÅäÖÃaction --> <!-- µÇ¼ÑéÖ¤µÄAction --> <action name="loginAction" class="loginCheckAction"> <result name="success">/WEB-INF/page/admin/index.jsp</result> <result name="input">/WEB-INF/page/admin/login.jsp</result> </action> <!-- SSHÏîÄ¿WEB-INFÏÂÃæµÄÒ³ÃæÌøתҪͨ¹ýServletÀ´ÊµÏÖ£¬ÕâÑùȷʵÊÇÂé·³Á˵㣬 ²»¹ý°²È«ÐÔ¾ÍÌá¸ßÉÏÈ¥ÁË£¬ÒòΪ·ÅÔÚWEB-INFÏÂÃæµÄJSPÒ³Ã棬ÊDz»¿ÉÒÔÖ±½Ó·ÃÎ浀 --> <action name="indexAction"> <result>/WEB-INF/page/admin/index.jsp</result> </action> <action name="gotoLoginAction"> <result>/WEB-INF/page/admin/login.jsp</result> </action> <!-- ѧÉúÐÅÏ¢¹ÜÀíµÄAction --> <action name="getAllStuInfoAction" class="studentAction" method="getAllInfo"> <result name="success">/WEB-INF/page/admin/student/studentInfoManager.jsp</result> </action> <action name="getStuInfoByIdAction" class="studentAction" method="getInfoById"> <result name="success">/WEB-INF/page/admin/student/studentInfoDetail.jsp</result> </action> <action name="getLearnScoresAction" class="studentAction" method="getLearnScoreById"> <result name="success">/WEB-INF/page/admin/student/studentLearnScores.jsp</result> </action> <action name="getMatchScoresAction" class="studentAction" method="getMatchScoreById"> <result name="success">/WEB-INF/page/admin/student/studentMatchScores.jsp</result> </action> <!-- ½ÌʦÐÅÏ¢¹ÜÀíµÄAction --> <action name="getAllTeaInfoAction" class="teacherAction" method="getAllInfo"> <result name="success">/WEB-INF/page/admin/teacher/teacherInfoManager.jsp</result> </action> <action name="getTeachingInfoAction" class="teacherAction" method="getTeachingInfoById"> <result name="success">/WEB-INF/page/admin/teacher/teacherTeaching.jsp</result> </action> <action name="getMatchGuideInfoAction" class="teacherAction" method="getMatchGuideInfoById"> <result name="success">/WEB-INF/page/admin/teacher/teacherMatchGuide.jsp</result> </action> <action name="getCourseStudentsInfoAction" class="teacherAction" method="getCourseStudentsInfoById"> <result name="success">/WEB-INF/page/admin/teacher/teacherCourseStusInfo.jsp</result> </action> <action name="getMatchStudentsInfoAction" class="teacherAction" method="getMatchStudentsInfoById"> <result name="success">/WEB-INF/page/admin/teacher/teacherMatchStusInfo.jsp</result> </action> <!-- ¿Î³Ì¹ÜÀíµÄAction --> <action name="getAllCourseInfoAction" class="courseAction" method="getAllInfo"> <result name="success">/WEB-INF/page/admin/course/courseManager.jsp</result> </action> <action name="getTeachersInfoAction" class="courseAction" method="getTeachersInfoById"> <result name="success">/WEB-INF/page/admin/course/courseTeachersInfo.jsp</result> </action> <!-- ±ÈÈüÐÅÏ¢¹ÜÀíµÄAction --> <action name="getAllMatchInfoAction" class="matchAction" method="getAllInfo"> <result name="success">/WEB-INF/page/admin/match/matchInfoManager.jsp</result> </action> <action name="getStudentsInfoAction" class="matchAction" method="getStudentsInfoById"> <result name="success">/WEB-INF/page/admin/match/matchStudentsInfo.jsp</result> </action> </package> </struts>
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN" "http://struts.apache.org/dtds/struts-2.3.dtd"> <!-- Struts2¿ò¼ÜÅäÖÃÎļþ --> <struts> <!-- ÅäÖÃstruts2¿ÉÒÔÊÜÀíµÄÇëÇóÀ©Õ¹Ãû --> <constant name="struts.action.extension" value="action,do,"></constant> <!-- struts2µÄpackage¶ÔÓ¦ÓÚÏîÄ¿µÄÄ£¿é --> <package name="action" extends="struts-default" namespace="/"> <!-- ÅäÖÃaction --> <!-- µÇ¼ÑéÖ¤µÄAction --> <action name="loginAction"> <result name="success">/WEB-INF/page/admin/index.jsp</result> <result name="input">/WEB-INF/page/admin/login.jsp</result> </action> <!-- SSHÏîÄ¿WEB-INFÏÂÃæµÄÒ³ÃæÌøתҪͨ¹ýServletÀ´ÊµÏÖ£¬ÕâÑùȷʵÊÇÂé·³Á˵㣬 ²»¹ý°²È«ÐÔ¾ÍÌá¸ßÉÏÈ¥ÁË£¬ÒòΪ·ÅÔÚWEB-INFÏÂÃæµÄJSPÒ³Ã棬ÊDz»¿ÉÒÔÖ±½Ó·ÃÎ浀 --> <action name="indexAction"> <result>/WEB-INF/page/admin/index.jsp</result> </action> <action name="gotoLoginAction"> <result>/WEB-INF/page/admin/login.jsp</result> </action> <!-- ѧÉúÐÅÏ¢¹ÜÀíµÄAction --> <action name="getAllStuInfoAction" method="getAllInfo"> <result name="success">/WEB-INF/page/admin/student/studentInfoManager.jsp</result> </action> <action name="getStuInfoByIdAction" method="getInfoById"> <result name="success">/WEB-INF/page/admin/student/studentInfoDetail.jsp</result> </action> <action name="getLearnScoresAction" method="getLearnScoreById"> <result name="success">/WEB-INF/page/admin/student/studentLearnScores.jsp</result> </action> <action name="getMatchScoresAction" method="getMatchScoreById"> <result name="success">/WEB-INF/page/admin/student/studentMatchScores.jsp</result> </action> <!-- ½ÌʦÐÅÏ¢¹ÜÀíµÄAction --> <action name="getAllTeaInfoAction" method="getAllInfo"> <result name="success">/WEB-INF/page/admin/teacher/teacherInfoManager.jsp</result> </action> <action name="getTeachingInfoAction" method="getTeachingInfoById"> <result name="success">/WEB-INF/page/admin/teacher/teacherTeaching.jsp</result> </action> <action name="getMatchGuideInfoAction" method="getMatchGuideInfoById"> <result name="success">/WEB-INF/page/admin/teacher/teacherMatchGuide.jsp</result> </action> <action name="getCourseStudentsInfoAction" method="getCourseStudentsInfoById"> <result name="success">/WEB-INF/page/admin/teacher/teacherCourseStusInfo.jsp</result> </action> <action name="getMatchStudentsInfoAction" method="getMatchStudentsInfoById"> <result name="success">/WEB-INF/page/admin/teacher/teacherMatchStusInfo.jsp</result> </action> <!-- ¿Î³Ì¹ÜÀíµÄAction --> <action name="getAllCourseInfoAction" method="getAllInfo"> <result name="success">/WEB-INF/page/admin/course/courseManager.jsp</result> </action> <action name="getTeachersInfoAction" method="getTeachersInfoById"> <result name="success">/WEB-INF/page/admin/course/courseTeachersInfo.jsp</result> </action> <!-- ±ÈÈüÐÅÏ¢¹ÜÀíµÄAction --> <action name="getAllMatchInfoAction" method="getAllInfo"> <result name="success">/WEB-INF/page/admin/match/matchInfoManager.jsp</result> </action> <action name="getStudentsInfoAction" method="getStudentsInfoById"> <result name="success">/WEB-INF/page/admin/match/matchStudentsInfo.jsp</result> </action> </package> </struts>
HibernateµÄÅäÖÃÎļþ´úÂ룺
[html] view plain copy print?
-
<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <!-- Generated by MyEclipse Hibernate Tools. --> <hibernate-configuration> <!-- Hibernate¿ò¼ÜÅäÖÃÎļþ --> <session-factory> <!-- ÅäÖÃsqlÓï¾ä¿ÉÒÔ´òÓ¡ÔÚ¿ØÖÆ̨ --> <property name="show_sql">true</property> <!--´´½¨SessionFactory¶ÔÏóʱ×Ô¶¯´´½¨Êý¾Ý±í --> <property name="hbm2ddl.auto">update</property> <!-- ÅäÖÃÓ³ÉäÎļþ --> <mapping resource="com/sgdata/po/Course.hbm.xml"/> <mapping resource="com/sgdata/po/Deptment.hbm.xml"/> <mapping resource="com/sgdata/po/Match.hbm.xml"/> <mapping resource="com/sgdata/po/Student.hbm.xml"/> <mapping resource="com/sgdata/po/StudentCourse.hbm.xml"/> <mapping resource="com/sgdata/po/StudentMatch.hbm.xml"/> <mapping resource="com/sgdata/po/Teacher.hbm.xml"/> <mapping resource="com/sgdata/po/TeacherCourse.hbm.xml"/> <mapping resource="com/sgdata/po/TeacherMatch.hbm.xml"/> </session-factory> </hibernate-configuration>
<?xml version='1.0' encoding='UTF-8'?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <!-- Generated by MyEclipse Hibernate Tools. --> <hibernate-configuration> <!-- Hibernate¿ò¼ÜÅäÖÃÎļþ --> <session-factory> <!-- ÅäÖÃsqlÓï¾ä¿ÉÒÔ´òÓ¡ÔÚ¿ØÖÆ̨ --> <property name="show_sql">true</property> <!--´´½¨SessionFactory¶ÔÏóʱ×Ô¶¯´´½¨Êý¾Ý±í --> <property name="hbm2ddl.auto">update</property> <!-- ÅäÖÃÓ³ÉäÎļþ --> <mapping resource="com/sgdata/po/Course.hbm.xml"/> <mapping resource="com/sgdata/po/Deptment.hbm.xml"/> <mapping resource="com/sgdata/po/Match.hbm.xml"/> <mapping resource="com/sgdata/po/Student.hbm.xml"/> <mapping resource="com/sgdata/po/StudentCourse.hbm.xml"/> <mapping resource="com/sgdata/po/StudentMatch.hbm.xml"/> <mapping resource="com/sgdata/po/Teacher.hbm.xml"/> <mapping resource="com/sgdata/po/TeacherCourse.hbm.xml"/> <mapping resource="com/sgdata/po/TeacherMatch.hbm.xml"/> </session-factory> </hibernate-configuration>
Ç°ÃæÄÇЩÅäÖÃÎļþÓаüº¬ÆäËüµÄ£¬Õâ¸öÒª¸ù¾Ý×Ô¼ºµÄÏîÄ¿ÐèҪȥ¸ÄµÄ^V^
ÏÂÃæÒÔѧÉúÐÅÏ¢¹ÜÀíµÄʵÏÖ¹ý³Ì½øÐÐ˵Ã÷£¬Ö»ËµÃ÷Õâ¸öÀý×Ó¹þ£¡
´´½¨POJOʵÌåÀࣺ
[java] view plain copy print?
-
import java.util.Date; import java.util.HashSet; import java.util.Set; /** * * ѧÉúÐÅÏ¢µÄʵÌåÀà * @author Nicky * */ public class Student { /* * ѧºÅ */ private String stuID; /* * °à¼¶ */ private String stuName; /* * ÐÔ±ð */ private String stuSex; /* * ³öÉúÄêÈÕ */ private Date stuBirth; /* * µç»° */ private String stuTel; /* * ÓÊÏä */ private String stuEmail; /* * רҵ */ private String dept; /* * Éí·ÝÖ¤ */ private String stuIDCard; /* * °à¼¶ */ private String className; /* * µÇ¼ÃÜÂë */ private String password; /* * ÊÇ·ñÊǹÜÀíÔ±µÄ±êÖ¾ 1±íʾÊÇ£¬0±íʾ²»ÊÇ */ private String isManager; public String getStuID() { return stuID; } public void setStuID(String stuID) { this.stuID = stuID; } public String getStuName() { return stuName; } public void setStuName(String stuName) { this.stuName = stuName; } public String getStuSex() { return stuSex; } public void setStuSex(String stuSex) { this.stuSex = stuSex; } public Date getStuBirth() { return stuBirth; } public void setStuBirth(Date stuBirth) { this.stuBirth = stuBirth; } public String getStuTel() { return stuTel; } public void setStuTel(String stuTel) { this.stuTel = stuTel; } public String getStuEmail() { return stuEmail; } public void setStuEmail(String stuEmail) { this.stuEmail = stuEmail; } public String getDept() { return dept; } public void setDept(String dept) { this.dept = dept; } public String getStuIDCard() { return stuIDCard; } public void setStuIDCard(String stuIDCard) { this.stuIDCard = stuIDCard; } public String getClassName() { return className; } public void setClassName(String className) { this.className = className; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getIsManager() { return isManager; } public void setIsManager(String isManager) { this.isManager = isManager; } }
import java.util.Date; import java.util.HashSet; import java.util.Set; /** * * ѧÉúÐÅÏ¢µÄʵÌåÀà * @author Nicky * */ public class Student { /* * ѧºÅ */ private String stuID; /* * °à¼¶ */ private String stuName; /* * ÐÔ±ð */ private String stuSex; /* * ³öÉúÄêÈÕ */ private Date stuBirth; /* * µç»° */ private String stuTel; /* * ÓÊÏä */ private String stuEmail; /* * רҵ */ private String dept; /* * Éí·ÝÖ¤ */ private String stuIDCard; /* * °à¼¶ */ private String className; /* * µÇ¼ÃÜÂë */ private String password; /* * ÊÇ·ñÊǹÜÀíÔ±µÄ±êÖ¾ 1±íʾÊÇ£¬0±íʾ²»ÊÇ */ private String isManager; public String getStuID() { return stuID; } public void setStuID(String stuID) { this.stuID = stuID; } public String getStuName() { return stuName; } public void setStuName(String stuName) { this.stuName = stuName; } public String getStuSex() { return stuSex; } public void setStuSex(String stuSex) { this.stuSex = stuSex; } public Date getStuBirth() { return stuBirth; } public void setStuBirth(Date stuBirth) { this.stuBirth = stuBirth; } public String getStuTel() { return stuTel; } public void setStuTel(String stuTel) { this.stuTel = stuTel; } public String getStuEmail() { return stuEmail; } public void setStuEmail(String stuEmail) { this.stuEmail = stuEmail; } public String getDept() { return dept; } public void setDept(String dept) { this.dept = dept; } public String getStuIDCard() { return stuIDCard; } public void setStuIDCard(String stuIDCard) { this.stuIDCard = stuIDCard; } public String getClassName() { return className; } public void setClassName(String className) { this.className = className; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getIsManager() { return isManager; } public void setIsManager(String isManager) { this.isManager = isManager; } }
ÅäÖÃStudent.hbm.xmlÎļþ
[html] view plain copy print?
-
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.sgdata.po"> <class name="Student" table="tb_students"> <id name="stuID" column="stuID" type="java.lang.String" length="11"> <generator class="assigned"></generator> </id> <property name="stuName" type="java.lang.String" length="30" not-null="true"></property> <property name="stuSex" type="java.lang.String" length="2" not-null="true"></property> <property name="stuBirth" type="java.util.Date" not-null="true"></property> <property name="stuTel" type="java.lang.String" length="20" not-null="true"></property> <property name="stuEmail" type="java.lang.String" length="20" not-null="true"></property> <property name="dept" type="java.lang.String" length="10" not-null="true"></property> <property name="stuIDCard" type="java.lang.String" length="20" not-null="true"></property> <property name="className" type="java.lang.String" length="20" not-null="true"></property> <property name="password" type="java.lang.String" length="10" not-null="true"></property> <property name="isManager" type="java.lang.String" length="1" not-null="false"></property> </class> </hibernate-mapping>
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd"> <hibernate-mapping package="com.sgdata.po"> <class name="Student" table="tb_students"> <id name="stuID" column="stuID" type="java.lang.String" length="11"> <generator></generator> </id> <property name="stuName" type="java.lang.String" length="30" not-null="true"></property> <property name="stuSex" type="java.lang.String" length="2" not-null="true"></property> <property name="stuBirth" type="java.util.Date" not-null="true"></property> <property name="stuTel" type="java.lang.String" length="20" not-null="true"></property> <property name="stuEmail" type="java.lang.String" length="20" not-null="true"></property> <property name="dept" type="java.lang.String" length="10" not-null="true"></property> <property name="stuIDCard" type="java.lang.String" length="20" not-null="true"></property> <property name="className" type="java.lang.String" length="20" not-null="true"></property> <property name="password" type="java.lang.String" length="10" not-null="true"></property> <property name="isManager" type="java.lang.String" length="1" not-null="false"></property> </class> </hibernate-mapping>
DAOʵÏÖ
[java] view plain copy print?
-
import java.util.List; import com.sgdata.po.Student; public interface StudentDao { /** * »ñÈ¡ËùÓÐѧÉúÐÅÏ¢ * @return */ public List<Student> getAllStudentInfo(); }
import java.util.List; import com.sgdata.po.Student; public interface StudentDao { /** * »ñÈ¡ËùÓÐѧÉúÐÅÏ¢ * @return */ public List<Student> getAllStudentInfo(); }
[java] view plain copy print?
-
public class StudentDaoImpl extends HibernateDaoSupport implements StudentDao { @Resource HibernateTemplate ht; /** * »ñÈ¡ËùÓÐÐÅÏ¢ */ public List<Student> getAllStudentInfo() { String sql = "from Student"; List<Student> students = (List<Student>) ht.find(sql); return students; } }
public class StudentDaoImpl extends HibernateDaoSupport implements StudentDao { @Resource HibernateTemplate ht; /** * »ñÈ¡ËùÓÐÐÅÏ¢ */ public List<Student> getAllStudentInfo() { String sql = "from Student"; List<Student> students = (List<Student>) ht.find(sql); return students; } }
ServiceʵÏÖ£º
[java] view plain copy print?
-
import java.util.List; import com.sgdata.po.Student; public interface StudentService { /** * »ñÈ¡ËùÓÐѧÉúÐÅÏ¢ * @return */ public List<Student> getAllStudentInfo(); } import java.util.List; import com.sgdata.po.Student; public interface StudentService { /** * »ñÈ¡ËùÓÐѧÉúÐÅÏ¢ * @return */ public List<Student> getAllStudentInfo(); } \[java\] view plain copy print?import java.util.List; import javax.annotation.Resource; import org.springframework.transaction.annotation.Transactional; import com.sgdata.dao.StudentDao; import com.sgdata.po.Student; import com.sgdata.service.StudentService; @Transactional(readOnly=false) public class StudentServiceBean implements StudentService { @Resource private StudentDao studentDao; public List<Student> getAllStudentInfo() { return studentDao.getAllStudentInfo(); } }
import java.util.List; import javax.annotation.Resource; import org.springframework.transaction.annotation.Transactional; import com.sgdata.dao.StudentDao; import com.sgdata.po.Student; import com.sgdata.service.StudentService; @Transactional(readOnly=false) public class StudentServiceBean implements StudentService { @Resource private StudentDao studentDao; public List<Student> getAllStudentInfo() { return studentDao.getAllStudentInfo(); } }
ActionʵÏÖ£º
[java] view plain copy print?
-
/** * ʵÏÖѧÉúÐÅÏ¢¹ÜÀíµÄActionÀà * */ public class StudentInfoManagerAction extends ActionSupport { /** * */ private static final long serialVersionUID = 1L; @Resource private StudentService studentService; //Ò³Êý int pagenum = 0; //ѧºÅ private String stuID; //ÐÕÃû private String stuName; //ÐÔ±ð private String stuSex; //³öÉúÄêÔ private String stuBirth; //µç»° private String stuTel; //ÓÊÏä private String stuEmial; //ϵ²¿ private String dept; //Éí·ÝÖ¤ private String stuIDCard; //°à¼¶ private String className; //ÃÜÂë private String password; /** * ѧÉú¶ÔÏóÀ´´¢´æѧÉúÐÅÏ¢ */ private Student student; /** * ѧÉúÐÅÏ¢µÄÁбí */ private List<Student> studentsInfo; /** * ѧÉúѧϰ³É¼¨µÄÐÅÏ¢Áбí */ private List learnScores; /** * ѧÉú±ÈÈü³É¼¨µÄÐÅÏ¢Áбí */ private List matchScores; public StudentInfoManagerAction(){ //student = new Student(); } public Student getStudent() { return student; } public void setStudent(Student student) { this.student = student; } public void setStudentsInfo(List<Student> studentsInfo){ this.studentsInfo = studentsInfo; } public List<Student> getStudentsInfo() { return studentsInfo; } public List getLearnScores() { return learnScores; } public void setLearnScores(List learnScores) { this.learnScores = learnScores; } public List getMatchScores() { return matchScores; } public void setMatchScores(List matchScores) { this.matchScores = matchScores; } public int getPagenum() { return pagenum; } public void setPagenum(int pagenum) { this.pagenum = pagenum; } public String getStuID() { return stuID; } public void setStuID(String stuID) { this.stuID = stuID; } public String getStuName() { return stuName; } public void setStuName(String stuName) { this.stuName = stuName; } public String getStuSex() { return stuSex; } public void setStuSex(String stuSex) { this.stuSex = stuSex; } public String getStuBirth() { return stuBirth; } public void setStuBirth(String stuBirth) { this.stuBirth = stuBirth; } public String getStuTel() { return stuTel; } public void setStuTel(String stuTel) { this.stuTel = stuTel; } public String getStuEmial() { return stuEmial; } public void setStuEmial(String stuEmial) { this.stuEmial = stuEmial; } public String getDept() { return dept; } public void setDept(String dept) { this.dept = dept; } public String getStuIDCard() { return stuIDCard; } public void setStuIDCard(String stuIDCard) { this.stuIDCard = stuIDCard; } public String getClassName() { return className; } public void setClassName(String className) { this.className = className; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } /** * »ñȡѧÉúµÄ»ù±¾ÐÅÏ¢ * @return * @throws Exception */ //@Override public String getAllInfo() throws Exception { studentsInfo = studentService.getAllStudentInfo(); return SUCCESS; } }
/** * ʵÏÖѧÉúÐÅÏ¢¹ÜÀíµÄActionÀà * */ public class StudentInfoManagerAction extends ActionSupport { /** * */ private static final long serialVersionUID = 1L; @Resource private StudentService studentService; //Ò³Êý int pagenum = 0; //ѧºÅ private String stuID; //ÐÕÃû private String stuName; //ÐÔ±ð private String stuSex; //³öÉúÄêÔ private String stuBirth; //µç»° private String stuTel; //ÓÊÏä private String stuEmial; //ϵ²¿ private String dept; //Éí·ÝÖ¤ private String stuIDCard; //°à¼¶ private String className; //ÃÜÂë private String password; /** * ѧÉú¶ÔÏóÀ´´¢´æѧÉúÐÅÏ¢ */ private Student student; /** * ѧÉúÐÅÏ¢µÄÁбí */ private List<Student> studentsInfo; /** * ѧÉúѧϰ³É¼¨µÄÐÅÏ¢Áбí */ private List learnScores; /** * ѧÉú±ÈÈü³É¼¨µÄÐÅÏ¢Áбí */ private List matchScores; public StudentInfoManagerAction(){ //student = new Student(); } public Student getStudent() { return student; } public void setStudent(Student student) { this.student = student; } public void setStudentsInfo(List<Student> studentsInfo){ this.studentsInfo = studentsInfo; } public List<Student> getStudentsInfo() { return studentsInfo; } public List getLearnScores() { return learnScores; } public void setLearnScores(List learnScores) { this.learnScores = learnScores; } public List getMatchScores() { return matchScores; } public void setMatchScores(List matchScores) { this.matchScores = matchScores; } public int getPagenum() { return pagenum; } public void setPagenum(int pagenum) { this.pagenum = pagenum; } public String getStuID() { return stuID; } public void setStuID(String stuID) { this.stuID = stuID; } public String getStuName() { return stuName; } public void setStuName(String stuName) { this.stuName = stuName; } public String getStuSex() { return stuSex; } public void setStuSex(String stuSex) { this.stuSex = stuSex; } public String getStuBirth() { return stuBirth; } public void setStuBirth(String stuBirth) { this.stuBirth = stuBirth; } public String getStuTel() { return stuTel; } public void setStuTel(String stuTel) { this.stuTel = stuTel; } public String getStuEmial() { return stuEmial; } public void setStuEmial(String stuEmial) { this.stuEmial = stuEmial; } public String getDept() { return dept; } public void setDept(String dept) { this.dept = dept; } public String getStuIDCard() { return stuIDCard; } public void setStuIDCard(String stuIDCard) { this.stuIDCard = stuIDCard; } public String getClassName() { return className; } public void setClassName(String className) { this.className = className; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } /** * »ñȡѧÉúµÄ»ù±¾ÐÅÏ¢ * @return * @throws Exception */ //@Override public String getAllInfo() throws Exception { studentsInfo = studentService.getAllStudentInfo(); return SUCCESS; } }
È»ºó¾Í¿ÉÒÔÔÚJSPÒ³ÃæÒýÈë
<%@ taglib uri="/struts-tags" prefix="s" %>
È»ºó»ñÈ¡Êý¾ÝÁË
\[html\]
<table class="table table-hover">
<tr>
<th width="120">ѧºÅ</th>
<th width="120">ÐÕÃû</th>
<th width="120">ÐÔ±ð</th>
<th width="120">°à¼¶</th>
<th width="120">ϵ²¿</th>
<th width="100">³öÉúÄêÔÂ</th>
<th width="100">²Ù×÷</th>
</tr>
<s:iterator value="studentsInfo" id="ssif" >
<tr>
<td><s:property value="#ssif.stuID" /></td>
<td><s:property value="#ssif.stuName" /></td>
<td><s:property value="#ssif.stuSex" /></td>
<td><s:property value="#ssif.className" /></td>
<td><s:property value="#ssif.dept" /></td>
<td><s:property value="#ssif.stuBirth" /></td>
<td>
<a class="button border-blue button-little" href="getStuInfoByIdAction?stuID=<s:property value='#ssif.stuID'/>">ÏêÇé</a>
<a class="button border-yellow button-little" href="getLearnScoresAction?stuID=<s:property value='#ssif.stuID' />" >ѧϰ</a>
<a class="button border-green button-little" href="getMatchScoresAction?stuID=<s:property value='#ssif.stuID' />">±ÈÈü</a>
</td>
</tr>
</s:iterator>
</table>
<table class="table table-hover"> <tr> <th width="120">ѧºÅ</th> <th width="120">ÐÕÃû</th> <th width="120">ÐÔ±ð</th> <th width="120">°à¼¶</th> <th width="120">ϵ²¿</th> <th width="100">³öÉúÄêÔÂ</th> <th width="100">²Ù×÷</th> </tr> <s:iterator value="studentsInfo" id="ssif" > <tr> <td><s:property value="#ssif.stuID" /></td> <td><s:property value="#ssif.stuName" /></td> <td><s:property value="#ssif.stuSex" /></td> <td><s:property value="#ssif.className" /></td> <td><s:property value="#ssif.dept" /></td> <td><s:property value="#ssif.stuBirth" /></td> <td> <a class="button border-blue button-little" href="getStuInfoByIdAction?stuID=<s:property value='#ssif.stuID'/>">ÏêÇé</a> <a class="button border-yellow button-little" href="getLearnScoresAction?stuID=<s:property value='#ssif.stuID' />" >ѧϰ</a> <a class="button border-green button-little" href="getMatchScoresAction?stuID=<s:property value='#ssif.stuID' />">±ÈÈü</a> </td> </tr> </s:iterator> </table>
ʵÏÖÊý¾Ý»ñÈ¡
ÕâÊÇÎÒ½áºÏBootstrapºÍSSH×öµÄ£¬½áºÏÀý×ÓÀ´ËµÃ÷ʵÏÖ¹ý³Ì£¬Ï£Íû¿ÉÒ԰ﵽѧϰµÄÈË£¬ÓÐÒÉ»óÇëÁôÑÔ¹þ