创建SpringBoot
启动一个新的SpringBoot项目
如图 右侧选择Spring Reactive Web
设置完成后点击“Generate”按钮,下载zip,然后将其解压到计算机上的一个文件夹中
在IDE中打开项目
找到src/main/java/com/example/demo中的DemoApplication.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);
}
}
在IDEA中运行这个程序,可以得到下图输出结果:
出现结果之后,打开浏览器进入网址Http://localhost:8080/hello
如图以下结果: