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>
  • 相关阅读:
    控制HTML Input只能输入数字和小数点
    VS中的路径宏 vc++中OutDir、ProjectDir、SolutionDir各种路径
    C# ListView用法详解
    wordpress学习五: 通过wordpress_xmlrpc的python包远程操作wordpress
    用IDEA开发简单的Servlet
    在centOS中安装mongodb
    simhash-- 一种文档去重的算法
    一个java实现的简单的4则运算器
    搭建ZooKeeper
    java入门--4111:判断游戏胜者-Who Is the Winner
  • 原文地址:https://www.cnblogs.com/hzhuxin/p/6674082.html
Copyright © 2011-2022 走看看