1)在官方初始化项目:勾选需要的集成组件,最后“Generate”下载maven项目
2)导入eclipse中(我的elicpse版本为:Version: 2018-12 (4.10.0))
项目结构:web包和HelloControler类,是我后续添加的
3)编写HelloController类:@RestController其实就是给@Controller类中所有的接口添加@ResponseBody效果
package com.example.demo.web;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class HelloController {
@GetMapping("/sayHi")
public String sayHi() {
return "hello springboot";
}
}
4)启动主方法,直接运行main方法即可,运行后,默认端口为8080
5)访问接口:http://localhost:8080/sayHi