以当前最新的版本来写这份学习的指导吧(2.2.5.RELEASE)
Spring Boot 2.2.5.RELEASE requires Java 8 and is compatible up to Java 13 (included). 文档上有这么一句话,说明了Spring Boot 2.2.5.RELEASE,需要的JDK的最低版本是 Java 8
Spring Initializr 创建
新建一个工程,项目名为:spring-boot-hello-world
项目创建成功之后,会生成一个以项目名称命名的类SpringBootHelloWorldApplication,可以认为是项目的入口,直接执行这个main方法,项目也是可以运行起来的。
package com.thrstones.springboothelloword;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringBootHelloWordApplication {
public static void main(String[] args) {
SpringApplication.run(SpringBootHelloWordApplication.class, args);
}
}
新建一个controller,编写方法进行测试即可
package com.thrstones.springboothelloword.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloWordController {
@RequestMapping("/")
public String sayHello(){
return "Hello Spring Boot!";
}
}
运行main方法,在浏览器中输入http://localhost:8080/,即可测试