什么是Spring MVC
Spring Web MVC是基于Servlet API构建的原始Web框架,从一开始就包含在Spring框架中。俗称“Spring MVC”
Spring MVC的特点
- 轻量级
- 高效、基于请求响应的MVC框架
- 兼容性好
- 约定大于配置
DispatcherServlet
Spring MVC是围绕着DispatcherServlet而设计Servlet,DispatcherServlet的作用是将请求分发到不同的处理器。
注:DispatcherServlet就是一个Servlet(它继承自HttpServlet基类)
DispatcherServlet请求处理流程
springmvc-servlet.xml
<?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 https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">
<!--扫描包-->
<context:component-scan base-package="com.controller" />
<!--过滤静态资源-->
<mvc:default-servlet-handler />
<!--开启注解,开启-->
<mvc:annotation-driven />
<!--视图解析器-->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="internalResourceViewResolver">
<!--前缀-->
<property name="prefix" value="/WEB-INF/jsp/" />
<!--后缀-->
<property name="suffix" value=".jsp" />
</bean>
</beans>