标签:pre ext 目录 逻辑 rop odi imp code mod
组件 | 说明 | |
---|---|---|
HandlerMapping | 将请求与拦截器列表一起映射到处理程序,以进行预处理和后期处理。映射基于某些标准,具体标准因HandlerMapping 实现而异。两个主要HandlerMapping实现是RequestMappingHandlerMapping (支持带@RequestMapping注释的方法)和SimpleUrlHandlerMapping (将URI路径模式显式注册到处理程序) | |
HandlerAdapter | 帮助DispatcherServlet调用映射到请求的处理程序,而不管实际如何调用该处理程序。主要目的HandlerAdapter是保护DispatcherServlet这些细节。 | |
HandlerExceptionResolver | 解析异常 | |
ViewResolver | String将从处理程序返回的基于逻辑的视图名称解析为实际的名称View ,以将其呈现给响应。 | |
LocaleResolver,LocaleContextResolver | 能够提供国际化的视图 | |
ThemeResolver |
<?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"
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">
<context:component-scan base-package="com.imooc.web"/>
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
@Configuration
@EnableWebMvc
public class WebMvcConfig implements WebMvcConfigurer {
@Bean
public ViewResolver viewResolver(){
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setViewClass(JstlView.class);
viewResolver.setPrefix("/WEB-INF/jsp/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new HandlerInterceptor() {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
System.out.println("addInterceptors.preHandle");
return true;
}
});
}
}
以上代码的@Configuration,@EnableWebMvc,@Bean相关代码替换以下xml配置
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/>
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"/>
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
配置@EnableWebMvc注解则会自动加载@Configuration的配置类
DelegatingWebMvcConfiguration中无@Bean,@Bean在WebMvcConfigurationSupport类中
相关代码
SpringBoot学习(五)重拾Spring Web MVC
标签:pre ext 目录 逻辑 rop odi imp code mod
原文地址:https://www.cnblogs.com/VVII/p/12462464.html