SpringMVC中的三大核心器

SpringMVC中的三大核心器

1、SpringMVC中的三大核心器是什么?

处理器映射器:RequestMappingHandlerMapping 处理器适配器:RequestMappingHandlerAdapter 视图解析器:InternalResourceViewResolver

其中处理器映射器,处理器解析器一般是配套使用。


2、三大核心器的配置,springMVC核心配置文件中配置

<?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:p="http://www.springframework.org/schema/p"
       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-4.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">

    <!-- 配置@Controller处理器,包扫描器 -->
    <context:component-scan base-package="com.pipi.springmvc.controller" />

    <!-- 配置处理器映射器 -->
    <!--<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" />-->
    <!-- 配置处理器适配器 -->
    <!--<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter" />-->

    <!-- 配置注解驱动,相当于同时配置了最新版本的处理器映射器,处理器适配器。对json数据提供支持 -->
    <mvc:annotation-driven />

    <!-- 配置视图解析器 -->
    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="jsp/" />
        <property name="suffix" value=".jsp" />
    </bean>

</beans>

3、三大核心器的使用流程图


经验分享 程序员 微信小程序 职场和发展