步骤:
- 创建springboot工程,并勾选web开发相关依赖
- 定义HelloController类,添加方法hello,并添加注解
- 运行测试
具体如下:

编写HelloController类:
c
package com.example.springbootwebquickstart;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
// 请求处理类
@RestController
public class HelloController {
@RequestMapping("/hello")
public String hello() {
System.out.println("Hello World");
return "Hello World ";
}
}
启动SpringBoot
访问8080