SpringBoot——》Thymeleaf
发布日期:2021-09-14 23:18:19 浏览次数:13 分类:技术文章

本文共 1187 字,大约阅读时间需要 3 分钟。

SpringBoot——》thymeleaf

一、项目依赖配置

org.springframework.boot
spring-boot-starter-thymeleaf

二、thymeleaf参数配置

参数对应jar包(版本可变动):spring-boot-autoconfigure-2.1.1.RELEASE.jar

参数对应java类:org.springframework.boot.autoconfigure.thymeleaf.ThymeleafProperties
注:在 application.ymlapplication.property 中配置
在这里插入图片描述

spring:  # 模板引擎  thymeleaf:    # Thymeleaf3.0模板:HTML (默认)、XML、TEXT、JAVASCRIPT、CSS、RAW    mode: HTML    encoding: utf-8    # 禁用缓存:避免改了模板还要重启服务器    cache: false  # 资源信息  messages:    # 国际化资源文件路径    basename: static/i18n/messages

1、默认模板存放路径

默认值:classpath:/templates/

可修改:

spring:  thymeleaf:    prefix:/templates/

2、默认模板后缀

默认值:.html

可修改:

spring:  thymeleaf:    suffix:.html

3、默认静态资源路径 (4种)

  • classpath:/META-INF/resources/
  • classpath:/resources/
  • classpath:/static/
  • classpath:/public/
    在这里插入图片描述

三、示例:Controller和index.html

src/main/java/com/controller下新建 WebController.java

import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.GetMapping; @Controllerpublic class WebController {
@GetMapping("/index") public String index(){
return "index"; }}

classpath:/resources/templates下新建 index.html

    
Title

我是小仙

转载地址:https://blog.csdn.net/weixin_43453386/article/details/102782945 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:读书有益——》余华
下一篇:Mysql——》limit分页

发表评论

最新留言

留言是一种美德,欢迎回访!
[***.207.175.100]2024年03月30日 10时58分46秒