使用IDEA创建使用 JDK8 的 2.x.x 版本的 Spring Boot 项目以及 Spring Boot 项目如何修改JDK版本
在 IntelliJ IDEA 中创建一个使用 JDK 8 的 Spring Boot 2.x 项目,你可以按照以下步骤操作:
- 打开 IntelliJ IDEA。
- 点击
Create New Project
。 - 在弹出的对话框中,选择
Spring Initializr
。 - 确保
Project SDK
设置为 JDK 8。 - 填写
Group
和Artifact
信息,以及其他相关配置。 - 选择
Spring Boot
的版本,通常是最新的 2.x 版本。 - 选择需要的依赖,比如 Web 依赖。
- 点击
Next
和Finish
来生成项目。
以下是一个简单的示例代码,展示了如何创建一个简单的 Spring Boot 2.x 应用程序:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
@RestController
class HelloController {
@GetMapping("/hello")
public String hello() {
return "Hello, Spring Boot 2!";
}
}
运行 main
方法启动你的 Spring Boot 应用程序,然后访问 http://localhost:8080/hello
查看结果。
评论已关闭