-
目标是创建第一个spring boot程序, 并且在浏览器能够输入'hello world'
-
1.创建项目
- 2.勾选Spring Web (注意, 选择2.7.x版本就行, 不用选最新的)
- 3.创建完之后, 删除多余的文件夹(.idea 也删掉)
- 4.创建Controller
- 5.编写代码
package com.itheima.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
// 添加Rest注解, 表示它是一个用于请求处理的类
@RestController
public class HelloController {
// 用注解定义请求路由
@RequestMapping("/hello")
public String hello() {
System.out.println("hello spring");
return "hello spring";
}
}
- 6.启动SpringBoot
- 7.打开浏览器 http://localhost:8080/hello 输出: hello spring