1.新建项目,选择Spring Initializr
2.直接finish,然后就等待下载各种包,大约10分钟左右
3.包变绿后,pom.xml中导入web依赖
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> <version>2.5.6</version> </dependency>
4.新建controller包,新建HelloController类
5.HelloController类
package com.kuang.controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class HelloController { @RequestMapping("/hello") public String hello() { return "Hello World"; } }
6.运行,访问8080,一个接口就成功了