您现在的位置是:亿华云 > IT科技类资讯
老师问我 Spring MVC 的工作流程
亿华云2025-10-03 20:17:14【IT科技类资讯】5人已围观
简介GitHub:https://github.com/nateshao/ssm/tree/master/106-springmvc-hello1. Spring MVC概述什么是Spring MVC?S
GitHub:https://github.com/nateshao/ssm/tree/master/106-springmvc-hello
1. Spring MVC概述
什么是老师Spring MVC?
Spring MVC是Spring提供的一个实现了Web MVC设计模式的轻量级Web框架。它与Struts2框架一样,作流都属于MVC框架,老师但其使用和性能等方面比Struts2更加优异。作流
Spring MVC具有以下特点:
是老师Spring框架的一部分,可以方便的作流利用Spring所提供的其他功能。 灵活性强,老师易于与其他框架集成。作流 提供了一个前端控制器DispatcherServlet,老师使开发人员无需额外开发控制器对象。作流 可自动绑定用户输入,老师并能正确的作流转换数据类型。 内置了常见的老师校验器,可以校验用户输入。作流如果校验不能通过,老师那么就会重定向到输入表单。 支持国际化。可以根据用户区域显示多国语言。 支持多种视图技术。它支持JSP、Velocity和FreeMarker等视图技术。 使用基于XML的云服务器提供商配置文件,在编辑后,不需要重新编译应用程序。2. 第一个Spring MVC应用
在IDEA中,创建一个名称为106-springmvc-hello的Web项目,具体参考:https://github.com/nateshao/ssm/tree/master/106-springmvc-hello
在web.xml中,配置Spring MVC的前端控制器DispatcherServlet。
dispatcher-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.nateshao"/> <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>hello.jsp
<%-- Created by IntelliJ IDEA. User: 邵桐杰 Date: 2021/10/16 Time: 16:13 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html> <head> <title>Title</title> </head> <body> <h2>hello springmvc</h2> </body> </html> <%-- 用EL表达式获取后台处理器封装的信息 --%> $END$控制台输出:
浏览器访问:http://localhost:8080/106_springmvc_hello_war_exploded/hello
3. Spring MVC的工作流程(重点!!!)
Spring MVC是如何工作的呢?(面试高频)
“通过入门案例的学习,相信读者对Spring MVC的使用已经有了一个初步的了解。在实际开发中,我们的实际工作主要集中在控制器和视图页面上,但Spring MVC内部完成了很多工作,这些程序在项目中具体是怎么执行的呢?接下来,将通过一张图来展示Spring MVC程序的执行情况。
总结
本章首先对Spring MVC框架进行了简单的介绍,
然后讲解了一个Spring MVC入门程序的编写,
最后通过入门案例对Spring MVC的工作流程进行了详细讲解。
通过本章的学习,我们能够了解什么是Spring MVC,以及Spring MVC的优点,掌握Spring MVC入门程序的编写,并能够熟悉Spring MVC框架的工作流程。
很赞哦!(465)
上一篇: 数据中心运营商转向AI以提高ROI和收入
下一篇: 什么是数据中心的交叉连接?