zoukankan      html  css  js  c++  java
  • springmvc spring mybatis框架整合

    web.xml
    1. <context-param>  
    2.         <param-name>contextConfigLocation</param-name>  
    3.         <param-value>classpath:spring-mybatis.xml</param-value>  
    4. </context-param> 
    1. <servlet>  
    2.         <servlet-name>SpringMVC</servlet-name>  
    3.         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>  
    4.         <init-param>  
    5.             <param-name>contextConfigLocation</param-name>  
    6.             <param-value>classpath:spring-mvc.xml</param-value>  
    7.         </init-param>  
    8.         <load-on-startup>1</load-on-startup>  
    9.         <async-supported>true</async-supported>  
    10. </servlet>  
     
     
    spring-mybatis.xml
    1.      <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"  
    2.         destroy-method="close">  
    3.         <property name="driverClassName" value="${driver}" />  
    4.         <property name="url" value="${url}" />  
    5.         <property name="username" value="${username}" />  
    6.         <property name="password" value="${password}" />  
    7.         <!-- 初始化连接大小 -->  
    8.         <property name="initialSize" value="${initialSize}"></property>  
    9.         <!-- 连接池最大数量 -->  
    10.         <property name="maxActive" value="${maxActive}"></property>  
    11.         <!-- 连接池最大空闲 -->  
    12.         <property name="maxIdle" value="${maxIdle}"></property>  
    13.         <!-- 连接池最小空闲 -->  
    14.         <property name="minIdle" value="${minIdle}"></property>  
    15.         <!-- 获取连接最大等待时间 -->  
    16.         <property name="maxWait" value="${maxWait}"></property>  
    17.     </bean>  
    18.   
    19.     <!-- spring和MyBatis完美整合,不需要mybatis的配置映射文件 -->  
    20.     <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">  
    21.         <property name="dataSource" ref="dataSource" />  
    22.         <!-- 自动扫描mapping.xml文件 -->  
    23.         <property name="mapperLocations" value="classpath:com/cn/hnust/mapping/*.xml"></property>  
    24.     </bean>  
    25.     <!-- 通过AOP配置提供事务增强,让service包下所有Bean的所有方法拥有事务 -->
    26.     <aop:config proxy-target-class="true">
    27.         <aop:pointcut id="serviceMethod"
    28.             expression=" execution(* com.service..*(..))" />
    29.         <aop:advisor pointcut-ref="serviceMethod" advice-ref="txAdvice" />
    30.     </aop:config>
    31.     <tx:advice id="txAdvice" transaction-manager="transactionManager">
    32.         <tx:attributes>
    33.             <tx:method name="*" />
    34.         </tx:attributes>
    35.     </tx:advice>
     
     

    spring-mvc.xml

    主要是自动扫描控制器,视图模式,注解的启动
     
    1. <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter" />
    2.      
    3. <!-- 配置视图解析器,将ModelAndView及字符串解析为具体的页面 -->
    4. <bean  class="org.springframework.web.servlet.view.InternalResourceViewResolver"
    5.     p:viewClass="org.springframework.web.servlet.view.JstlView" 
    6.     p:prefix="/WEB-INF/jsp/"
    7.     p:suffix=".jsp" />
     
     
     
     
     
  • 相关阅读:
    PAT (Advanced Level) Practice 1071 Speech Patterns (25分)
    PAT (Advanced Level) Practice 1070 Mooncake (25分)
    PAT (Advanced Level) Practice 1069 The Black Hole of Numbers (20分)
    PAT (Advanced Level) Practice 1074 Reversing Linked List (25分)
    PAT (Advanced Level) Practice 1073 Scientific Notation (20分)
    第一次冲刺个人总结01
    构建之法阅读笔记01
    人月神话阅读笔记01
    四则运算2
    学习进度条(软件工程概论1-8周)
  • 原文地址:https://www.cnblogs.com/lnas01/p/5157121.html
Copyright © 2011-2022 走看看