最近在学习springboot做一下记录
首先在pom.xml中导入thymeleaf依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
然后是在application.properties中写配置
spring.thymeleaf.cache=false
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
(注意!!)文件名一定要叫templates
然后就是在resources中创建文件夹templates(注意文件名不能错)
在templates文件夹中创建html文件
HTML内容我就不贴了 随便写
(笔者在文件夹名字被坑了一把 springboot中thymeleaf默认路径是templates不对的话会路径报错)
然后控制层中写个类调用Controller.java
@RequestMapping(value ="/index" , method = RequestMethod.GET)
String index() {
System.out.println("欢迎进入温度管理系统!");
return "index";
}
return后面写要返回的页面名称
注意·:Controller类名上要使用注解@Controller
不能使用@restController否则会直接返回返回值里的字段而不是返回到页面
总结·:springboot确实好用但是坑有点多- -