当前位置:编程学习 > JAVA >>

ssh 这和配置文件示例

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <filter>
   <filter-name>struts2</filter-name>
   <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>
  <filter-mapping>
   <filter-name>struts2</filter-name>
   <url-pattern>/*</url-pattern>
  </filter-mapping>
  <listener>
   <listener-class>
   org.springframework.web.context.ContextLoaderListener
   </listener-class>
  </listener>
</web-app>

struts-config.xml

<?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>
     <package name="ssh2" extends="struts-default">
     <action name="saveUser" class="saveUserAction">
     <result name="success" type="redirect">listUser.action</result>
     </action>
     <action name="listUser" class="findUserAllAction">
     <result name="success">/userlist.jsp</result>
     </action>
     <action name="deleteUser" class="deleteUserAction">
     <result name="success" type="redirect">listUser.action</result>
     </action>
     <action name="updatePUser" class="getOneUserAction">
     <result name="success">/getoneuser.jsp</result>
     </action>
     <action name="updateUser" class="updateUser">
     <result name="success" type="redirect">listUser.action</result>
     </action>
     </package>
    </struts>

applicationContext.xml

<?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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">


<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName">
<value>com.mysql.jdbc.Driver</value>
</property>
<property name="url" value="jdbc:mysql://localhost:3306/ssh"></property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>
<bean id="sessonFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource"/>
</property>
<property name="mappingResources">
<list>
<value>com/test/bean/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 name="transactionManger" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessonFactory"></property>
</bean>

<bean id="userDao" class="com.test.dao.impl.UserDAOImpl" scope="singleton">
<property name="sessionFactory">
<ref local="sessonFactory"/>
</property>
</bean>
<bean id="userServiceTarget" class="com.test.service.impl.UserServiceImpl">
<property name="userDao" ref="userDao"></property>
</bean>
<bean id="userService" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="target" ref="userServiceTarget"></property>
<property name="transactionManager" ref="transactionManger"></property>
<property name="transactionAttributes">
<props>
<prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
<bean id="saveUserAction" class="com.test.action.user.UserSaveAction">
<property name="service" ref="userService"></property>
</bean>
<bean id="findUserAllAction" class="com.test.action.user.UserFindAllAction">
<property name="service" ref="userService"></property>
</bean>
<bean id="deleteUserAction" class="com.test.action.user.UserDeleteAction" scope="singleton">
<property name="service" ref="userService"></property>
</bean>
<bean id="getOneUserAction" class="com.test.action.user.UserUpdatePAction">
<property name="service" ref="userService"></property>
</bean>
<bean id="updateUser" class="com.test.action.user.UserUpdateAction">
<property name="service" ref="userService"></property>
</bean>
</beans>

User.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.test.bean.User" table="ssh_user">
<id name="id" column="id" type="int">
<generator class="increment"><!-- 主键id的生成方式为自增长   -->
</generator>
</id>
<property name="firstname" column="firstname" type="string"></property>
<property name="lastname" column="lastname" type="string"></property>
<property name="age" column="age" type="integer"></property>
</class>
</hibernate-mapping> --------------------编程问答-------------------- 话说spring的食物不是最好用advice和aop那对基友了么
补充:Java ,  Java EE
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,