zoukankan      html  css  js  c++  java
  • spring mvc常用配置

    <?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: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/context http://www.springframework.org/schema/context/spring-context-4.3.xsd
            http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd">
    
        <mvc:annotation-driven validator="validator">
            <mvc:message-converters>
                <bean
                    class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter4" >
                    <property name="supportedMediaTypes">  
                   <list>  <!-- 下面不配通过restful工具测试时会报错 -->
                          <value>text/plain;charset=utf-8</value>  
                          <value>text/html;charset=utf-8</value>  
                          <value>text/json;charset=utf-8</value>  
                          <value>application/json;charset=utf-8</value>  
                    </list>  
               </property>
               </bean>
            </mvc:message-converters>
        </mvc:annotation-driven>

          <!--防止跨域请求出错-->

        <mvc:cors>
          <mvc:mapping path="/xxx/**" allowed-origins="*"/>
        </mvc:cors>

          <!--拦截器配置-->
        <mvc:interceptors>
          <mvc:interceptor>
            <mvc:mapping path="/xxx/**"/>
              <bean class="com.xxx.interceptor.SecurityInterceptor"></bean>
            </mvc:interceptor>
        </mvc:interceptors>

        <!-- Freemarker配置 -->
        <bean id="freemarkerConfig"
            class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
            <property name="templateLoaderPath" value="/WEB-INF/views/" />
            <property name="freemarkerSettings">
                <props>
                    <prop key="defaultEncoding">UTF-8</prop>
                    <prop key="url_escaping_charset">UTF-8</prop>
                    <prop key="locale">zh_CN</prop>
                    <prop key="localized_lookup">false</prop>
                    <prop key="classic_compatible">true</prop>
                    <prop key="number_format">0.######</prop>
                    <prop key="datetime_format">yyyy-MM-dd HH:mm:ss</prop>
                    <prop key="date_format">yyyy-MM-dd</prop>
                    <prop key="time_format">HH:mm:ss</prop>
                    
                </props>
            </property>
        </bean>
    
        <mvc:view-resolvers>
            <bean 
                class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
                <property name="contentType" value="text/html;charset=UTF-8" />
                <property name="cache" value="true" />
                <property name="prefix" value="" />   <!--此处配置和freemarkerConfig的相关配置路径是结合的 -->
    <property name="suffix" value=".html" />
    </bean>
    <mvc:jsp prefix="/WEB-INF/jsp/" suffix=".jsp" />
    </mvc:view-resolvers>

    <context:component-scan base-package="xxx.yyyy.web" />

    <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean">
    <property name="providerClass" value="org.hibernate.validator.HibernateValidator" />
    </bean>

    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
    <!-- <property name="maxUploadSize" value="100000"/> -->
    </bean>

    </beans>
  • 相关阅读:
    Allegro PCB Design GXL (legacy) 使用slide无法将走线推挤到焊盘的原因
    OrCAD Capture CIS 16.6 导出BOM
    Altium Designer (17.0) 打印输出指定的层
    Allegro PCB Design GXL (legacy) 将指定的层导出为DXF
    Allegro PCB Design GXL (legacy) 设置十字大光标
    Allegro PCB Design GXL (legacy) 手动更改元器件引脚的网络
    magento产品导入时需要注意的事项
    magento url rewrite
    验证台湾同胞身份证信息
    IE8对css文件的限制
  • 原文地址:https://www.cnblogs.com/hzhuxin/p/6674082.html
Copyright © 2011-2022 走看看