- mvn:3.6.3,能够拉取pom中的依赖和打包即可
- java:1.8.0_202,尽量8.0往上,一般新版本jdk是在旧版本上更新迭代的
- ide:idea 2021.2.2(ultimate Edition),专业版,功能较多
前期准备:一个集成开发环境(IDE),JDK 1.8 以上;阅读说明:https://spring.io/quickstart
1、打开 https://start.spring.io/,在开启的对话框内进行配置的选择
- 选择 SpringBoot 版本时,建议选择最新的发布版本(release),非快照版本(snapshot)
- 选择添加依赖,添加 Spring Web,并将生成的压缩包下载
2. 编写代码
使用 IDE 打开解压后后压缩包,并向 src/main/java/com/example/demo/DemoApplication.java 其中添加代码
java
package com.example.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
@GetMapping("/hello")
public String hello(@RequestParam(value = "name", defaultValue = "World") String name) {
return String.format("Hello %s!", name);
}
}
3. 运行程序
终端通过mvn运行程序或者通过idea编译启动
# 终端启动方式 mvnw spring-boot:run2.2 通过 IDEA 建立 SpringBoot项目
过程上面类似,选择 file – new – project – spring initial – 设置jdk版本,添加依赖;添加接口与2.1中一致



