前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >SpringBoot整合Thymeleaf快速入门

SpringBoot整合Thymeleaf快速入门

作者头像
九转成圣
发布2024-04-10 17:35:19
710
发布2024-04-10 17:35:19
举报
文章被收录于专栏:csdncsdn

SpringBoot整合Thymeleaf快速入门

引入依赖

代码语言:javascript
复制
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

修改配置文件

代码语言:javascript
复制
spring.thymeleaf.cache=false
# 默认前置
spring.thymeleaf.prefix=classpath:/templates/
# 默认后缀
spring.thymeleaf.suffix=.html

Controller

代码语言:javascript
复制
@Controller
public class HelloThymeleafController {
    @RequestMapping("/hello")
    public String hello(Model model){
        model.addAttribute("hello","hello welcome");
        // 找classpath:/templates/hello.html
        return "hello";
    }
}

在resources下创建templates目录

templates中创建hello.html文件

代码语言:javascript
复制
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <title>Thymeleaf的入门</title>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<!--输出hello数据-->
<p th:text="${hello}"></p>
</body>
</html>

访问http://localhost:8080/hello

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2024-04-10,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • SpringBoot整合Thymeleaf快速入门
  • 引入依赖
  • 修改配置文件
  • Controller
  • 在resources下创建templates目录
  • templates中创建hello.html文件
  • 访问http://localhost:8080/hello
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档