一、新建一个Meven项目,编写pom.xml,添加必要的依赖。
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example</groupId> <artifactId>myproject</artifactId> <version>0.0.1-SNAPSHOT</version> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.3.1.RELEASE</version> </parent> <description/> <developers> <developer/> </developers> <licenses> <license/> </licenses> <scm> <url/> </scm> <url/> <!-- Additional lines to be added here... --> </project>
二、创建一个Java文件,编写代码,内容如下。
import org.springframework.boot.*; import org.springframework.boot.autoconfigure.*; import org.springframework.web.bind.annotation.*; @RestController @EnableAutoConfiguration public class Example { @RequestMapping("/") String home() { return "Hello World!"; } public static void main(String[] args) { SpringApplication.run(Example.class, args); } }
三、运行main方法。
四、打开浏览器,输入http://localhost:8080/,应该会看到浏览器输出:Hello World!
相关学习资料
springboot官网:https://docs.spring.io/spring-boot/docs/2.3.1.RELEASE/reference/html/index.html
b站:https://www.bilibili.com/video/BV1Et411Y7tQ?from=search&seid=3537728523864607960