SpringBoot——》Thymeleaf

一、项目依赖配置

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

二、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;
 
@Controller
public class WebController {
 
    @GetMapping("/index")
    public String index(){
        return "index";
    }
}

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

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>我是小仙</h1>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值