spring-web.xml 模版备忘

spring-web

<?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.xsd 
 http://www.springframework.org/schema/mvc 
 http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd"> 
 
<!-- HandlerMapping 无需配置,SpringMVC可以默认启动,DefaultAnnotationHandlerMapping annotation-driven HandlerMapping --> 
 
<!-- 配置SpringMVC --> 
<!-- 1.开启SpringMVC注解模式 --> 
<!-- 简化配置: (1)自动注册DefaultAnootationHandlerMapping,AnotationMethodHandlerAdapter 
 (2)提供一些列:数据绑定,数字和日期的format @NumberFormat, @DateTimeFormat, xml,json默认读写支持 --> 
<mvc:annotation-driven/> 
 
<!-- 2.静态资源默认servlet配置 
 (1)加入对静态资源的处理:js,gif,png 
 (2)允许使用"/"做整体映射 , 不会拦截,当为静态资源。 
 这两个都是处理静态资源的,区别可以理解成一个是指定一个自定义的serlvet来专门处理相应的静态资源,如果不指定 
 会默认找default名字的servlet 
 而<mvc:resources>的好处可以理解成是静态资源可以在我们项目中的任意位置配置,只需要将对应的位置声明即可 
 --> 
<mvc:resources mapping="/resources/**" location="/resources/"/> 
<mvc:default-servlet-handler/> 
 
<!-- 3.定义视图解析器 --> 
<!-- ViewResolver:视图解析器。可以配置多个 但是一定要将这个ViewResolver(InternalResourceViewResolver) 
 放到最后 --> 
<!-- 解析json格式的传参和封装数据到页面,注意spring的版本和对应的配置方式 --> 
<!-- spring-4.2以后 --> 
<bean id="viewResolver" 
 class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
<property name="prefix" value="/WEB-INF/html/"></property> 
<property name="suffix" value=".html"></property> 
</bean> 
 
<!-- 4.扫描web相关的bean --> 
<!-- 激活组件扫描功能,扫描aop的相关组件组件 --> 
<context:component-scan base-package="com.ryanjie.o2o.web"/> 
 
</beans>

转自@Ryanjie,原创链接:https://www.cnblogs.com/Ryanjie/p/10142701.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值