初识Spring MVC(入门笔记)

什么是Spring MVC

Spring Web MVC是基于Servlet API构建的原始Web框架,从一开始就包含在Spring框架中。俗称“Spring MVC”

Spring MVC的特点

  1. 轻量级
  2. 高效、基于请求响应的MVC框架
  3. 兼容性好
  4. 约定大于配置

DispatcherServlet

Spring MVC是围绕着DispatcherServlet而设计Servlet,DispatcherServlet的作用是将请求分发到不同的处理器。
注:DispatcherServlet就是一个Servlet(它继承自HttpServlet基类)

DispatcherServlet请求处理流程

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>

版权声明:本文为qq_41911599原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。