Post

springmvc_01

springmvc_01

spring MVC

MVC 的分离思想:

把整个应用程序中和用户进行交互的功能代码归纳在一起,这部分代码整体称为 V (View 或叫视图层) 把专门用来进行数据传递或数据逻辑处理的功能代码归纳在一起,称其为 M(Model 或叫l模型层) 因为V 和 M 是要经常交流、沟通的,V 需要展示 M 处理过的数据,同时,M 也可能需要 V 提供的用户交互时输入的数据。虽然分了,但两者之间存在依赖关系。我们不让 V 和 M 直接交流,而是在两者之间引入了一个叫做 C(控制器)的对象,所以说 C 就是 V 和 M 之间的桥梁!

Spring MVC 项目中提供 2 个 WebApplicationContext 对象:

  • WebApplicationContext 对象用来创建 Spring MVC 相关的组件,称其为 Web 上下文对象 ;
  • RootApplicationContext 用来创建程序中其它的具体功能组件(如逻辑组件、数据层访问组件…),称其为 Root (根)上下文对象 。

DispatcherServlet 的组件(本质就是一个 Servlet),此组件用来作为进入程序的唯一入口。

可称 DispatcherServlet 为中央控制器或前端控制器。

依赖

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<dependencies>
	<dependency>
		<groupId>junit</groupId>
		<artifactId>junit</artifactId>
		<version>4.13.2</version>
		<scope>test</scope>
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-context</artifactId>
		<version>5.3.30</version>
		<scope>compile</scope>
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-web</artifactId>
		<version>5.3.30</version>
		<scope>compile</scope>
	</dependency>
	<dependency>
		<groupId>org.springframework</groupId>
		<artifactId>spring-webmvc</artifactId>
		<version>5.3.30</version>
	</dependency>
	<dependency>
		<groupId>javax.servlet</groupId>
		<artifactId>javax.servlet-api</artifactId>
		<version>4.0.1</version>
		<scope>provided</scope>
	</dependency>
	<dependency>
		<groupId>org.testng</groupId>
		<artifactId>testng</artifactId>
		<version>RELEASE</version>
		<scope>compile</scope>
	</dependency>
</dependencies>
This post is licensed under CC BY 4.0 by the author.