一、SpringMVC简介
Spring MVC属于SpringFrameWork的后续产品,已经融合在Spring Web Flow里面。Spring 框架提供了构建 WEB 应用程序的全功能 MVC 模块。使用 Spring 可插入的 MVC 架构,从而在使用Spring进行WEB开发时,可以选择使用Spring的Spring MVC框架或集成其他MVC开发框架,如Struts1(现在一般不用),Struts 2(一般老项目使用)等等。
二、整合SpringMVC
pom.xml中导入SpringMVC依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.1.8.RELEASE</version>
</dependency>
然后在项目内新建IndexController,代码如下
package com.example.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* IndexController
*
* @Author: HanYong
* @CreateTime: 2021-05-13
*/
@RestController
public class IndexController {
@RequestMapping("/")
public String index(){
return "hello word";
}
}
启动项目...
访问项目
我的项目端口是8765,所以直接在浏览器访问 http://localhost:8765/
三、SpringMVC配置修改
1.官方文档地址
官方文档里面都有相关配置介绍,直接按需修改就行
https://docs.spring.io/spring-framework/docs/current/reference/html/web.html