环境准备
- JDK 17
- Maven 3.6.1
- Spring Boot 2.5.6
- IDEA 社区版本
初始化项目
- 通过官网进行初始化项目
下载地址:https://spring.io/projects/spring-boot
- 配置生成项目
- 通过IDEA 导入下载的项目
- 通过编写hello world 代码和启动项目
// 添加 controller 包,写HelloController类
package com.example.helloworld.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
// http://localhost:8080/hello
@RequestMapping("/hello")
public String hello(){
return "hello world!";
}
}
运行结果: