1. 程式人生 > >springmybatisspringmvc整合配置檔案

springmybatisspringmvc整合配置檔案

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/mvc
        http://www.springframework.org/schema/mvc/spring-mvc.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd">
    <!-- 1.告訴SpringMVC的註解在哪裡 -->
    <!-- 掃描控制器包,如果有spring掃描controller會導致父子容器問題,出現宣告式事務無效,事務無法回滾 -->
    <context:component-scan base-package="com.yh.*.controller"></context:component-scan>
    <!-- 2.註解驅動,讓註解生效 -->
    <mvc:annotation-driven/>
    <!-- 3.配置檢視解析器,負責解析出真正的物理檢視 ,分散式開發,需要寫ID
        後臺返回邏輯檢視:index
        解析出真正的物理檢視:字首+邏輯檢視+字尾===/WEB-INF/jsp/index+字尾.jsp-->
        <!-- <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        字首
        <property name="prefix" value="/WEB-INF/jsp/"></property>
        字尾
        <property name="suffix" value=".jsp"></property>
        </bean> -->
      <!-- 配置freemarker模板檔案字首,模板檔案編碼 -->  
    <bean id="freeMarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath" value="/WEB-INF/jsp/"></property>
<property name="defaultEncoding" value="UTF-8"></property>
<property name="freemarkerSettings">
<props>
            <prop key="template_update_delay">0</prop>  
            <prop key="default_encoding">UTF-8</prop>  
            <prop key="number_format">0.##########</prop>  
            <prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>  
            <prop key="classic_compatible">true</prop>  
            <prop key="template_exception_handler">ignore</prop>  
</props>
</property>
</bean>
<!-- 配置freemakrer檢視解析字尾,頁面顯示檢視編碼 -->
<bean class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
<property name="suffix" value=".ftl"></property>
<property name="contentType" value="text/html;charset=utf-8"></property>
</bean>
        
    <!-- 4.配置檔案上傳解析器Multipart解析器 -->
     <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
      <property name="defaultEncoding" value="UTF-8"></property>
      </bean> 
    <!-- 如果碰見請求中/js/xx格式請求,去location配置的/js中去尋找, -->
    <!-- 如果沒有配置mvc:resources去尋找@requestmapping -->
    <mvc:resources location="/WEB-INF/js/" mapping="/js/**"></mvc:resources>
    <mvc:resources location="/WEB-INF/images/" mapping="/images/**"></mvc:resources>
    <mvc:resources location="/WEB-INF/css/" mapping="/css/**"></mvc:resources>
    <mvc:resources location="/WEB-INF/jsp/" mapping="/jsp/**"></mvc:resources>
    <mvc:resources location="/WEB-INF/pic/" mapping="/pic/**"></mvc:resources>
    <!--5.攔截器 -->
<mvc:interceptors>
<!--多個攔截器,順序執行 -->
<mvc:interceptor>
<mvc:mapping path="/**"/>
<bean class="com.yh.filter.interceptor.HandlerInterceptor"></bean>
</mvc:interceptor>
<mvc:interceptor>
<mvc:mapping path="/**"/>
<bean class="com.yh.filter.interceptor.HandlerInterceptor2"></bean>
</mvc:interceptor>
</mvc:interceptors>
    
</beans>