springboot 静态资源 和 thymleaf模板引擎和thymleaf语法_配置首页

5、配置首页

server.servlet.context-path=/jinhua

http://localhost:8080/jinhua/





4、thymleaf 数组




3、一个简单spring boot的thmleaf引擎





2、thymleaf模板引擎

thymleaf配置类中,指定了前缀和后腿(spring的视图解析器需手动配置,springboot的thymeleaf 自动配置好),我们只需导入对应的依赖即可使用该模板。

依赖:

<dependency>
    <groupId>org.thymeleaf</groupId>
    <artifactId>thymeleaf-spring5</artifactId>
</dependency>
<dependency>
    <groupId>org.thymeleaf.extras</groupId>
    <artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>

使用:templates中保存 html页面,controller 类 返回到页面





1、项目中如下4个路径下可存放静态资源
@ConfigurationProperties(prefix = "spring.resources", ignoreUnknownFields = false)
public class ResourceProperties {

   private static final String[] CLASSPATH_RESOURCE_LOCATIONS = { "classpath:/META-INF/resources/",
         "classpath:/resources/",  "classpath:/static/", "classpath:/public/" };

可以在项目中创建如下文件,存放静态资源,默认有classpath:/static/路径

访问的优先级:resources > static > public

发布了120 篇原创文章 · 获赞 12 · 访问量 11万+

猜你喜欢

转载自blog.csdn.net/ljj123_/article/details/105338195
今日推荐