自定义视图前后缀与Thymeleaf的使用

自定义视图前后缀

spring.resources.static-location默认参数指定了Spring Boot-web项目中静态文件存放地址,该参数默认设置为:classpath:/static,classpath:/public,classpath:/resources,classpath:/META-INF/resources,servlet context:/

可以发现这些地址中并没有/templates这个地址。

 

spring.resources.static-location

设置静态资源路径(一般不建议使用):  

spring:
resources:
static-locations: [classpath:templates/,classpath:public/,classpath:static/]

static-locations 不建议使用 所以我们的html只能存放到springBoot默认的资源访问路径

自定义视图前后缀:

spring:
mvc:
view:
prefix: html/
suffix: .html

 

 

Thymeleaf的使用

导入Thymeleaf

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

Thymeleaf模版默认会使用templates作为视图文件下

HTML文件头

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" lang="zh/cn">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
</html>

thymeleaf 基本语法thymeleaf官网

posted on 2021-12-13 20:03  每天积极向上  阅读(397)  评论(0编辑  收藏  举报

导航