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>
  • 相关阅读:
    【转载】nio介绍+原理+传统IO原理+与传统IO区别+案例
    【Ubuntu】制作执行脚本 | 打包一串命令顺序执行
    Ubuntu 使用教程集锦
    【转载】自定义地图数据瓦片化请求的一种实现方案
    【转载】ROS机器人程序设计 | 期末知识点大总结
    【转载】三维重建(三)相机参数标定与光束平差法(Bundle Adjustment)
    【阅读笔记】《大话数据挖掘》定义和功能
    【转载】C++对象成员与构造函数
    【转载】IP地址和子网划分学习笔记之《子网掩码详解》
    STM32的启动过程一
  • 原文地址:https://www.cnblogs.com/hzhuxin/p/6674082.html
Copyright © 2011-2022 走看看