微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

06_MyBatis,Spring,SpringMVC整合


  1. 项目结构

  1. Spring的配置:

beans.xml

<?xml version=1.0 encoding=UTF⑻?>

<beans xmlns=http://www.springframework.org/schema/beans

    xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance

    xmlns:mvc=http://www.springframework.org/schema/mvc

    xmlns:context=http://www.springframework.org/schema/context

    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⑶.0.xsd

       http://www.springframework.org/schema/mvc

       http://www.springframework.org/schema/mvc/spring-mvc⑶.0.xsd

       http://www.springframework.org/schema/context

       http://www.springframework.org/schema/context/spring-context⑶.0.xsd

       http://www.springframework.org/schema/aop

       http://www.springframework.org/schema/aop/spring-aop⑶.0.xsd

       http://www.springframework.org/schema/tx

       http://www.springframework.org/schema/tx/spring-tx⑶.0.xsd >                      

      

       <context:component-scan base-package=com.rl/>

      

       <bean id=dataSource class=org.springframework.jdbc.datasource.DriverManagerDataSource>

           <property name=driverClassName value=com.MysqL.jdbc.Driver></property>

           <url jdbc:MysqL://localhost:3306/mybatis></username root></password 123456></property>

       </bean>

      

       <!--

           使用spring来管理sqlSessionFactory

        -->

       <sqlSessionFactory org.mybatis.spring.sqlSessionfactorybean>

           <configLocation classpath:sqlMapConfig.xml></ref=dataSource></bean>

      

       <txManager org.springframework.jdbc.datasource.DataSourceTransactionManager>

           <tx:advice txAdvice transaction-manager=txManager>

           <tx:attributes>

              <tx:method save* propagation=required/>

              <update* delete* select* read-only=true/>

           </tx:attributes>

       </tx:advice>

      

       <aop:config>

           <aop:advisor advice-ref=pointcut=execution(* com.rl.service..*.*(..))/>

       </aop:config>

</beans>

@H_502_800@
  1. springmvc.xml的配置内容以下:

<?       http://www.springframework.org/schema/tx/spring-tx⑶.0.xsd >                       

      

       <com.rl.controller/>

       <org.springframework.web.servlet.view.InternalResourceViewResolver>

           <prefix /WEB-INF/jsp/></suffix .jsp></bean>

</ web.xml的配置内容以下:

<?web-app http://java.sun.com/xml/ns/javaee xmlns:web=http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd

    http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd

    WebApp_ID 2.5>

   

    <listener>

       <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

    </listener>

    <context-param>

       <param-name>contextConfigLocation</param-name>

       <param-value>classpath:beans.xml</param-value>

    </context-param>

   

    <servlet>

       <servlet-name>springmvc</servlet-name>

       <servlet-class>org.springframework.web.servlet.dispatcherServlet</servlet-class>

       <init-param>

           <param-name>

           <param-value>classpath:springmvc.xml</param-value>

       </init-param>

    </servlet>

    <servlet-mapping>

       <url-pattern>*.do</url-pattern>

    </servlet-mapping>

   

    <filter>

        <filter-name>SpringCharacterEncodingFilter</filter-name>

        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>

        <init-param>

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐