<!--thymeleaf--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <!--nekohtml 解决thymealeaf标签闭合问题--> <dependency> <groupId>net.sourceforge.nekohtml</groupId> <artifactId>nekohtml</artifactId> <version>1.9.14</version> </dependency>
|- src |- main |- resources |- templates
经常使用属性 spring.thymeleaf.cache 是否开启模板缓存,默认true spring.thymeleaf.encoding 指定模板的编码,默认为: UTF-8 spring.thymeleaf.prefix 指定模板的前缀,默认为:classpath:/templates/ spring.thymeleaf.suffix 指定模板的后缀,默认为:.html spring.thymealeaf.mode 指定模板的模式, 默认为:HTML5 (若是使用了nekohtml依赖 设置为LEGACYHTML5)
参考 xixicat SpringBoot配置属性之MVChtml
路径:src.main.resoruces.templates
demo.htmljava
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <!-- 未导入nekohtml依赖且修改mode时,此处需闭合,不然会报错 --> <title>Thymealeaf Page</title> </head> <body> <h1>Hello Thymealeaf!</h1> </body> </html>
路径:src.main.java.域名反写.项目名.controllerspring
@Controller public class IndexController { @RequestMapping("demo") public String demo(){ return "demo"; } }
参考 纯洁的微笑 springboot(四):thymeleaf使用详解缓存