SSH练习随笔

来源:互联网 发布:linux系统启动级别 编辑:程序博客网 时间:2024/04/29 01:11

SSH练习随笔

导入SSH架包

1.在struts-config.xml中,加插件:  <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">      <set-property property="contextConfigLocation" value="/WEB-INF/applicationContext.xml" />   </plug-in>2.写*.jsp,action,actionform3.在struts-config.xml的action中type要改为:"org.springframework.web.struts.DelegatingActionProxy"

4.在applicationContext.xml中声明每个action  <bean name="/login" class="com.aiguo.struts.action.LoginAction" singleton="false"> <property name="userDAO">    <ref bean="userDAOProxy" /> </property>  </bean>5.写service6.在applicationContext.xml中加入数据库连接,配置sessionFactory,事务处理  <!-- dataSource --> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">  <property name="driverClassName">   <value>com.mysql.jdbc.Driver</value>  </property>  <property name="url">   <value>jdbc:mysql://localhost/test</value>  </property>  <property name="username">   <value>root</value>  </property>  <property name="password">   <value>root</value>  </property> </bean> <!-- 配置sessionFactory, 注意这里引入的包的不同  --> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">  <property name="dataSource">   <ref local="dataSource" />  </property>  <property name="mappingResources">   <list>    <value>com/aiguo/hibernate/User.hbm.xml</value>   </list>  </property>  <property name="hibernateProperties">   <props>    <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>    <prop key="hibernate.show_sql">true</prop>   </props>  </property> </bean>

 <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">  <property name="sessionFactory">   <ref local="sessionFactory" />  </property> </bean>

 <bean id="userDAO" class="com.aiguo.dao.UserDAOImp">  <property name="sessionFactory">   <ref local="sessionFactory" />  </property> </bean>   <!-- 事务处理  --> <bean id="userDAOProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">  <property name="transactionManager">   <ref bean="transactionManager" />  </property>  <property name="target">   <ref local="userDAO" />  </property>  <property name="transactionAttributes">   <props>    <prop key="insert*">PROPAGATION_REQUIRED</prop>    <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>    <prop key="is*">PROPAGATION_REQUIRED,readOnly</prop>   </props>  </property> </bean>7.写DAO

8.建数据库9.写PO,写*.hbm.xml文件

原创粉丝点击