Spring Boot 12之 thymeleaf
来源:互联网 发布:wwwtaoyitu淘宝号查询 编辑:程序博客网 时间:2024/05/18 13:07
整体步骤:
(1) 在pom.xml中引入thymeleaf;
(2) 如何关闭thymeleaf缓存
(3) 编写模板文件.html
spring Boot默认就是使用thymeleaf模板引擎的,所以只需要在pom.xml加入依赖即可:
1、 在pom.xml中引入thymeleaf;
org.springframework.boot
spring-boot-starter-thymeleaf
2、在 src/main/resources/templates下加入Thymeleaf模板。
Thymeleaf缓存在开发过程中,肯定是不行的,那么就要在开发的时候把缓存关闭,
只需要在application.properties进行配置即可:
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
thymeleaf start
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-8
spring.thymeleaf.content-type=text/html
开发时关闭缓存,不然没法看到实时页面
spring.thymeleaf.cache=false
在spring-boot下,默认约定了Controller试图跳转中thymeleaf模板文件的的前缀prefix是”classpath:/templates/”,后缀suffix是”.html”
这个在application.properties配置文件中是可以修改的。
如下配置可以修改试图跳转的前缀和后缀
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
3、创建一个Controller
@Controller
public class TemplateController {
/**
* 返回html模板.
*/
@RequestMapping(“/helloHtml”)
public String helloHtml(Model model){
model.addAttribute(“hello”,”from TemplateController.helloHtml”);
return “/helloHtml”;
}
@RequestMapping(“/helloHtml2”)
public String helloHtml(Map
- Spring Boot 12之 thymeleaf
- Spring Boot 系列之 thymeleaf
- [spring-boot] thymeleaf 热交换
- Spring Boot + Gradle + Thymeleaf
- spring boot 整合 thymeleaf
- spring boot vue Thymeleaf
- spring boot thymeleaf 用法
- Spring Boot使用Thymeleaf
- Spring-Boot thymeleaf异常
- spring-boot集成thymeleaf
- Spring Boot整合thymeleaf
- Spring Boot+Spring Security+Thymeleaf
- Thymeleaf系列一 Spring boot 集成Thymeleaf
- Spring-Boot初学之配置文件application.properties(thymeleaf模板)
- Spring Boot之旅:Java模版引擎Thymeleaf详解(一)
- spring boot thymeleaf错误之Circular view path [...]
- Spring Boot学习之旅:(十二)模版引擎-Thymeleaf
- Spring Boot学习(四)之web开发渲染页面 -- Thymeleaf
- Java设计模式(观察者模式)
- VirtualBox环境下Debian安装增强工具失败
- 关于apache配置阿里云证书https的步骤(详细)
- 求最大公约数代码
- VS2013 error C4996:'*****':This function or variable may be unsafe办法
- Spring Boot 12之 thymeleaf
- PAT.Basic level.T.1013.数素数
- 前台服务
- Spring Boot 13 之freemarker
- repo 工具的获取
- 64位寄存器
- QT SYSZUXpinyin 开源输入法移植
- jbpm工作流引擎常用API与基本流程操作
- 【ionic+angulajs】ion-tabs访问页面url不记录历史的方法(修改浏览器记录的历史url,改变goback的跳转)