日期:2014-05-16 浏览次数:20496 次
前些天做了个学生信息的管理系统 无非是些信息的增删改查 ?这次用了ssh2不用模拟数据库了
注意点:
1.jar包
2.applicationContext.xml ?struts.xml ?hibernate.cfg.xml ?mode中类和映射文件User.hbm.xml
3.配置稍稍有点不同 ?
用hibernateTemplate配置了sessionFactory在dao中配置了hibernateTemplate ?也可以直接配置seesionFactory
?
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"> <property name="sessionFactory" ref="sessionFactory"></property> </bean>
4.在struts.xml中配置action 中的class必须和对应在applicationContext.xml的<bean id="***Action" class="com.***.action.**Action"> id的名字相对应,这样网页提交的action才能用spring实例化的对象
5.在(用User做对象)UserAction 中 声明userService ?或者在UserService中声明UserDAO的时候最好用接口声明
用的是动态代理 ?当然用类直接声明也是可以的 ?用的就是CGILB代理
6.dao要extends ?HibernateDaoSupport ?
下面放spring 和struts的配置?
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd"> <beans> <bean id="userAction" class="com.aowin.action.UserAction" scope="prototype"> <property name="userService" ref="userService"></property> </bean> <bean id="userService" class="com.aowin.serviceimpl.UserServiceImpl"> <property name="userDAO" ref="userDAO"></property> </bean> <bean id="userDAO" class="com.aowin.daoimpl.UserDAOImpl"> <property name="hibernateTemplate" ref="hibernateTemplate"></property> </bean> <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="configLocation" value="classpath:hibernate.cfg.xml"></property> </bean> <!-- 负责开启、提交事务 --> <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"> <property name="transactionManager" ref="transactionManager"></property> <property name="transactionAttributes"> <props> <prop key="*">PROPAGATION_REQUIRED</prop> </props> </property> </bean> <bean id="autoproxy" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"> <property name="beanNames" value="*Service"></property> <property name="interceptorNames" value="transactionInterceptor"></property> </bean> </beans>
?struts
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.devMode" value="true" /> <package name="default" namespace="/user" extends="struts-default"> <action name="userlist" class="userAction" method="getUsers"> <result>/list.jsp</result> </action> <action name="input" class="userAction" method="addInput"> <result>/input.jsp</result> </action> <action name="update" class="userAction" method="update"> <result>/update.jsp</result> </action> <action name="updatedo" class="userAction" method="updatedo"> <result name="input">/result.jsp</result> <result>/result.jsp</result> </action> <action name="delete" class="userAction" method