springmvc.xml

本文详细介绍了Spring MVC框架的配置过程,包括使用XML进行bean定义、注解扫描、视图解析器配置、静态资源过滤、消息转换器设置及上传大小限制等关键步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4        xmlns:mvc="http://www.springframework.org/schema/mvc"
 5        xmlns:context="http://www.springframework.org/schema/context"
 6        xmlns:aop="http://www.springframework.org/schema/aop"
 7        xmlns:tx="http://www.springframework.org/schema/tx"
 8        xsi:schemaLocation="
 9         http://www.springframework.org/schema/beans
10         https://www.springframework.org/schema/beans/spring-beans.xsd
11         http://www.springframework.org/schema/mvc
12         https://www.springframework.org/schema/mvc/spring-mvc.xsd
13         http://www.springframework.org/schema/context
14         https://www.springframework.org/schema/context/spring-context.xsd
15             http://www.springframework.org/schema/aop
16       http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
17       http://www.springframework.org/schema/tx
18       http://www.springframework.org/schema/tx/spring-tx-3.2.xsd">
19 
20     <!--    开启注解扫描,只扫描controller注解-->
21     <context:component-scan base-package="com.lu">
22         <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
23     </context:component-scan>
24     <!--    配置的视图解析器-->
25     <bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
26         <property name="prefix" value="/WEB-INF/pages/"></property>
27         <property name="suffix" value=".jsp"></property>
28     </bean>
29     <!--过滤静态资源-->
30     <mvc:resources mapping="/css/**" location="/css/"></mvc:resources>
31     <mvc:resources mapping="/images/**" location="/images/"></mvc:resources>
32     <mvc:resources mapping="/js/**" location="/js/"></mvc:resources>
33     <!--    开启springmvc注解的支持-->
34     <mvc:annotation-driven>
35         <mvc:message-converters>
36             <!--json编码设置-->
37             <!--第一种消息转换器spring自带的,fastjson和jackson共有-->
38             <bean class="org.springframework.http.converter.StringHttpMessageConverter">
39                 <property name="supportedMediaTypes">
40                     <list>
41                         <value>application/json;charset=UTF-8</value>
42                     </list>
43                 </property>
44             </bean>
45             <!--第二种消息转换器fastjson独有的,自动将ajax的返回参数转换为json格式,控制器可直接return对象-->
46        <!--     <bean class="com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter">
47                 <property name="supportedMediaTypes">
48                     <list>
49                         <value>test/html;charset=UTF-8</value>
50                         <value>application/json</value>
51                     </list>
52                 </property>
53             </bean>-->
54         </mvc:message-converters>
55     </mvc:annotation-driven>
56     <mvc:default-servlet-handler/>
57 
58     <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
59         <property name="maxUploadSize" value="10240000"></property>
60     </bean>
61 </beans>

 

转载于:https://www.cnblogs.com/Lcyan/p/11105326.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值