1、spirng Initializr:
选择jdk8,
选择maven project
默认地址: https://start.spring.io/
国内地址: http://start.springboot.io
阿里巴巴: https://start.aliyun.com/
2、SpringBoot Web容器
org.springframework.boot spring-boot-starter-web3、创建控制器:
@RestController
public class HelloController {
@GetMapping()
@ResponseBody
public String root(){
return “root”;
}
@GetMapping(“/hello”)
@ResponseBody
public String hello(){
return “hello”;
}
}
4、配置文件改成:
application.yml
内容:
# 开发环境配置
server:
# 服务器的HTTP端口,默认为80
port: 8088
5、添加thymeleaf模板:
org.springframework.boot spring-boot-starter-thymeleaf修改controller:
@GetMapping()
public ModelAndView root(){
ModelAndView mav = new ModelAndView();
mav.setViewName(“root”);
return mav;
}
templates文件夹中添加root.html
运行程序