1、新建springboot项目
使用阿里云的链接创建项目速度更快,https://start.aliyun.com/
版本随便选,选新的就好了
选择项目新建的目录,点击finish就创建成功了
建好后的项目目录是这样的
2、添加控制器controller
添加新建文件夹controller,在controller下新建类HelloWorldController
添加代码到HelloWorldController中
package com.example.springboothelloworlddemo.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloWorldController {
@RequestMapping("/hello")
public String helloWorld() {
return "Hello World";
}
}
3、启动项目,测试运行
先启动项目,在浏览器输入地址:http://127.0.0.1:8080/hello