java常用视图模板
springboot目录结构:

thymeleaf
springboot推荐的模板,在pom.xml中引入thymeleaf的起步依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
模板文件放在templates文件夹下,springboot默认去这个文件夹下解
析,如下使用(更多关于thymeleaf语法可查看官网文档):

若要更改模板文件位置,可在application配置文件中修改:
dir则是在resources目录下新建的文件夹,有多级就写多级 /xxxx/xxx/

开发中可以把缓存关闭,无需重新启动即可看到更改效果

IDEA设置:


freemarker
在pom.xml中引入freemarker的起步依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
application配置:
#关闭freemarker缓存
spring.freemarker.cache=false
#freemarker模板位置
spring.freemarker.template-loader-path=classpath:/templates/
#freemarker文件后缀
spring.freemarker.suffix=.ftl
使用(获取后台传过来的数据):

更多freemarker的语法参照 freemarker官网或freemarker中文官网
本文探讨了Spring Boot中Thymeleaf与Freemarker两种常用模板引擎的使用方法、配置与特性,帮助开发者理解选择与迁移策略。
2206

被折叠的 条评论
为什么被折叠?



