SpringMVC配置文件

springMVC-servlet.xml springMVC配置 放在resources下

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       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.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc.xsd">
    <!--基于beanname的方式-->
    <!--    <bean name="/testmvc" class="com.j3071.mvc.controller.BeanNameController"></bean>-->

    <!--注解映射的方式-->
    <context:component-scan base-package="com.j3071.oneshop.controller"/><!--包扫描路径-->
    <!--配置注解驱动-->
    <mvc:annotation-driven>
        <!--设置不使用默认的消息转换器-->
        <mvc:message-converters register-defaults="false">
            <!--配置spring的转换器-->
            <bean class="org.springframework.http.converter.StringHttpMessageConverter"/>
            <bean class="org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter"/>
            <bean class="org.springframework.http.converter.ByteArrayHttpMessageConverter"/>
            <bean class="org.springframework.http.converter.BufferedImageHttpMessageConverter"/>
            <!--配置fastjson中实现HttpMessageConverter接口的转换器-->
            <bean id="fastJsonHttpMessageConverter"
                  class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
                <!--加入支持的媒体类型,返回contentType-->
                <property name="supportedMediaTypes">
                    <list>
                        <!--这里顺序不能反,一定要先写text/html,不然IE下会出现下载提示-->
                        <value>text/html;charset=UTF-8</value>
                        <value>application/json;charset=UTF-8</value>
                    </list>
                </property>
                <property name="fastJsonConfig">
                    <bean class="com.alibaba.fastjson.support.config.FastJsonConfig">
                        <property name="serializerFeatures">
                            <list>
                                <value>WriteMapNullValue</value>
                                <value>WriteNullNumberAsZero</value>
                                <value>WriteNullListAsEmpty</value>
                                <value>WriteNullStringAsEmpty</value>
                                <value>WriteNullBooleanAsFalse</value>
                                <value>WriteDateUseDateFormat</value>
                            </list>
                        </property>
                    </bean>
                </property>

            </bean>
        </mvc:message-converters>
    </mvc:annotation-driven>

    <!--配置静态资源路径-->
    <!--第一种-->
    <mvc:resources mapping="/css/**" location="/css/"/>
    <mvc:resources mapping="/images/**" location="/images/"/>
    <mvc:resources mapping="/js/**" location="/js/"/>
    <mvc:resources mapping="/fonts/**" location="/fonts/"/>

    <!--第二种-->
    <!--    <mvc:default-servlet-handler/>-->

    <!--配置解析物理地址的方式-->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/"/><!--jsp的路径 如果在jsp包下 /jsp/-->
        <property name="suffix" value=".jsp"/><!--后缀-->
    </bean>
    <!-- 文件上传配置 -->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="maxUploadSize" value="20000000"/>
        <property name="defaultEncoding" value="utf-8"/>
    </bean>


</beans>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值