对于springMVC 的配置文件理解

一 、入口:web.xml

<?xml version="1.0" encoding="UTF-8"?>

Archetype Created Web Application

org.springframework.web.context.ContextLoaderListener contextConfigLocation classpath:applicationContext.xml spring org.springframework.web.servlet.DispatcherServlet spring / encodingFilter org.springframework.web.filter.CharacterEncodingFilter encoding UTF-8 forceEncoding true encodingFilter /* index.jsp

二、spring-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>

<!-- 上下文相关的注解能被spring bean 进行管理 -->
<context:annotation-config />

<!-- 启动注解驱动的spring mvc 功能 -->
<mvc:annotation-driven/>

<mvc:interceptors>
    <bean class="com.egov.common.HttpInterceptor" />
</mvc:interceptors>

<!-- 启动包扫描功能 -->
<context:component-scan base-package="com.egov.controller" />
<context:component-scan base-package="com.egov.service" />

<mvc:resources location="/js/" mapping="/js/**"/>
<mvc:resources location="/css/" mapping="/css/**"/>
<mvc:resources location="/bootstrap3.3.5/" mapping="/bootstrap3.3.5/**"/>
<mvc:resources location="/assets/" mapping="/assets/**"/>
<mvc:resources location="/ztree/" mapping="/ztree/**"/>

<bean class="com.egov.common.ApplicationContextHelper" lazy-init="false" />

<!-- 当我们来定义一个spring mvc 接口的时候,会使用RequestMapping,这个类会找到我们定义的RequestMapping的注解,
如:@RequestMapping("/login.do"),相当于是去使用什么样的代码去处理。
 -->
<!--<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" />-->

<bean class="com.egov.common.SpringExceptionResolver" />

<!-- BeanNameViewResolver它相当于是告诉我们的MVC项目,当我来一个请求之后,我格式的数据返回给它,
例如我们返回json数据,或者jsp页面,甚至可以下载文件,如pdf文件、js、css等 是做我们的视图渲染的
当我们使用BeanNameViewResolver的时候,我需要额外做一些配置,需要指定json做处理
  -->
<bean class="org.springframework.web.servlet.view.BeanNameViewResolver" />

<!-- 指定json做处理
相当于是把我们定义的RequestMapping下面的类,期望是以json返回的时候,会使用下面这个类来处理
-->
<bean id="jsonView" class="org.springframework.web.servlet.view.json.MappingJackson2JsonView" />

<!-- jsp 返回 下面 bean 处理
对jsp页面做指令
-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <!-- prefix 请求路径前缀 -->
    <property name="prefix" value="/WEB-INF/views/" />
    <!-- suffix 请求文件后缀 -->
    <property name="suffix" value=".jsp" />
</bean>

三、

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值