文章来源于网络收集而来,版权归原创者所有,如有侵权请及时联系!
模版引擎?
看别人写的博客中谈到了一个叫 thymeleaf 的模板引擎,查了一番,发现好像就是一个在前后端不分离的情况下数据渲染的工具吧。有查到一个概念 ——前后端分离,通过 vue.js+SpringBoot 作前后端分离,通过 fetch ,ajax 等异步请求 java 封装的数据接口。高内聚低耦合,想想还是前后端分离一切组件化更优秀,所以模版引擎只是简单看一下
Thymeleaf 模版引擎,官方推荐的视图层模板引擎,提供了对 Thymeleaf 的自动化配置解决方案。需要在 pom 中添加该依赖,如下:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
以下是 ThymeleafProperties 配置类部分源码
@ConfigurationProperties(prefix = "spring.thymeleaf")
public class ThymeleafProperties {
private static final Charset DEFAULT_ENCODING = StandardCharsets.UTF_8;
public static final String DEFAULT_PREFIX = "classpath:/templates/";
public static final String DEFAULT_SUFFIX = ".html";
/**
* Whether to check that the template exists before rendering it.
*/
private boolean checkTemplate = true;
/**
* Whether to check that the templates location exists.
*/
private boolean checkTemplateLocation = true;
/**
* Prefix that gets prepended to view names when building a URL.
*/
private String prefix = DEFAULT_PREFIX;
//...
}
下图是类中几个属性的默认值,可以在 application.properties 中通过前缀 spring.thymeleaf.xxx
自定义配置
属性 | 默认值 | 含义 |
---|---|---|
checkTemplate | true | 注册前是否检测模版存在 |
checkTemplateLocation | true | 是否检测模版存在 |
prefix | classpath:/templates/ | 模版位置 |
suffix | .html | 后缀 |
mode | HTML | 模版模型 |
encoding | StandardCharsets.UTF_8 | 文件编码 |
cache | true | 模版是否缓存 |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论