SSH中的各xml文件写法

1、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">
 
 <!-- web.xml Order:context-param=>listener=>filter=>servlet -->
 
 <context-param>
  <param-name>contextConfigLocation</param-name>
  <param-value>
   classpath*:applicationContext*.xml
  </param-value>
 </context-param>
 
 <listener>
  <listener-class>
   org.springframework.web.context.ContextLoaderListener
  </listener-class>
 </listener>
 
 <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>*.action</url-pattern>
 </filter-mapping>
 
 <filter>
   <filter-name>encodingFilter</filter-name>
   <filter-class>
  org.springframework.web.filter.CharacterEncodingFilter
   </filter-class>
   <init-param>
    <param-name>encoding</param-name>
    <param-value>UTF-8</param-value>
   </init-param>
   <init-param>
    <param-name>forceEncoding</param-name>
    <param-value>true</param-value>
   </init-param>
 </filter>
 <servlet>
  <servlet-name>startup</servlet-name>
  <servlet-class>
   com.yuanit.sys.util.StartupServlet
  </servlet-class>
  <load-on-startup>2</load-on-startup>
 </servlet>
</web-app>

 

 

2、struts.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>
 <!-- 动态方法调用 -->
 <constant name = "struts.enable.DynamicMethodInvocation" value = "true"></constant>
 <package name = "main" extends = "json-default">
  
  
  <interceptors>
   
   <interceptor name="userSession" class="com.yuanit.app.interceptor.UserSessionInterceptor"/>
   <interceptor name = "testOne" class = "com.yuanit.app.interceptor.TestOneInterceptor"/>
   <interceptor-stack name="interceptorStack">
    <interceptor-ref name="defaultStack" />
     <interceptor-ref name="userSession" />
      
        </interceptor-stack>    
  </interceptors>
  <default-interceptor-ref name = "interceptorStack"/>
  <global-results>
   <result name="login" type="redirect">/Admin_goLogin.action</result>
   <result name = "input" type="freemarker">template/app/Admin/error.ftl</result>
   <result name = "error" type = "freemarker">template/app/Admin/error.ftl</result>
   <result name = "json" type = "json">
    <param name = "includeProperties">
     resultInfo/.success,resultInfo/.message
    </param>
   </result>
  </global-results>
  <action name="*_*" class="com.yuanit.app.action.{1}Action" method="{2}">
   <result name="json" type="json">
    <param name="includeProperties">
     resultInfo/.success,resultInfo/.message
    </param>
   </result>
   <result name="freemarker" type="freemarker">template/app/{1}{2}.ftl</result>    
         </action>
 </package>
</struts>

 


3、hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
 "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
 "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
 <session-factory>
  <!-- jdbc驱动程式 -->
  <property name = "connection.driver_class">com.mysql.jdbc.Driver</property>
  <!-- jdbcURL-->
  <property name = "connection.url">jdbc:mysql://localhost:3306/ydas</property>
  <!-- 用户 -->
  <property name = "connection.username">root</property>
  <!-- 密码-->
  <property name = "connection.password">root</property>
  <!-- SQL方言 -->
  <property name = "dialect">org.hibernate.dialect.MySQLDialect</property>
  <!-- 显示实际操作时的sql -->
  <property name = "show_sql">fale</property>
  <!--自动提交-->
  <property name = "connection.autocommit">true</property>
  <!--物件与资料库表格映射文件-->
  <mapping resource="com/yuanit/app/model/Member.hbm.xml"/>
  <mapping resource="com/yuanit/app/model/Role.hbm.xml"/>
  <mapping resource = "com/yuanit/app/model/Permission.hbm.xml"/>
  <mapping resource = "com/yuanit/app/model/Log.hbm.xml"/>
 </session-factory>
</hibernate-configuration>

4、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:aop="http://www.springframework.org/schema/aop"
 xmlns:tx="http://www.springframework.org/schema/tx"
 xsi:schemaLocation="
  http://www.springframework.org/schema/beans
  http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
  http://www.springframework.org/schema/aop
  http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
  http://www.springframework.org/schema/tx
  http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"
  default-autowire="byName"
  default-merge="true">
  
 <!--session工厂 --> 
 <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
  <property name="configLocation">
   <value>classpath:hibernate.cfg.xml</value>
  </property>
 </bean>
 
 
 <!-- 配置事务管理器 -->
 
 <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
  <property name="sessionFactory">
   <ref bean="sessionFactory"/>
  </property>
 </bean>
 <!--事务通知 -->
 <tx:advice id="smAdvice" transaction-manager="transactionManager">
  <tx:attributes>
   <tx:method name="save*" propagation="REQUIRED"/>
   <tx:method name="delete*" propagation="REQUIRED"/>
   <tx:method name="edit*" propagation="REQUIRED"/>
   <tx:method name="*" propagation="SUPPORTS" read-only="true" />
  </tx:attributes>
 </tx:advice>
 <!--Spring AOP confignation -->
 
 <aop:config>
  <aop:pointcut id="smMethod" expression="execution(* com.yuanit.app.service.impl.*ServiceImpl.*

(..))" />
  <aop:advisor pointcut-ref="smMethod" advice-ref="smAdvice" />
 </aop:config> 
 
 <!--具体注入--> 
 <bean id = "memberDAO" class = "com.yuanit.app.dao.impl.MemberDAOImpl"/>
 <bean id = "memberService" class = "com.yuanit.app.service.impl.MemberServiceImpl"/>
 <bean id="memberAction" class="com.yuanit.app.action.MemberAction" scope="prototype"></bean>
</beans>

 


5、X.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.yuanit.app.model.XXX" table = "xxx" catalog = "ydas">
  <id name = "id" type = "java.lang.Integer">
   <column name = "id" length = "50"/>
   <generator class = "native"/>
  </id>
  <property name = "roleName" type = "java.lang.String">
   <column name = "role_name" length = "50"/>
  </property>
  <property name = "rolePermissions" type = "java.lang.String">
   <column name = "role_permissions" length = "50"/>
  </property>
 </class>
</hibernate-mapping>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值