`
李楷呀
  • 浏览: 4238 次
社区版块
存档分类
最新评论

springboot 中使用 thymeleaf 模板

阅读更多

       springboot 中使用 thymeleaf 模板,首先我们需要在pom文件中引入thymeleaf,

 

       <dependency>

         <groupId>org.springframework.boot</groupId>

         <artifactId>spring-boot-starter-thymeleaf</artifactId>

        </dependency>

 

       接下来编写我们的模板文件src/main/resources/templates/test.html

       

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"

      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">

    <head>

        <title>Test Hello World!</title>

    </head>

    <body>

        <h1 th:inline="text">test</h1>

        <p th:text="${test}"></p>

    </body>

 

</html>

 

接下来编写我们的controller 

 

import java.util.Map;

 

import org.springframework.stereotype.Controller;

import org.springframework.web.bind.annotation.RequestMapping;

 

@Controller

public class TestController {

 

/**

 

     * 返回thymeleaf 模板 页面

 

     */

    @RequestMapping("/test")

    public String test(Map<String,Object> map){

       map.put("test","test");

       return"/test";

    }

 

 

 

}

 

启动应用,输入http://localhost:8080/test就会显示我们的页面了,我们的页面中会显示test。

 

我们在开发过程中需要关闭thymeleaf缓存,不然我们修改了模板会看不到效果,关闭方法是在application.properties配置文件中配置:

spring.thymeleaf.cache=false

 

 

 

 

1
0
分享到:
评论

相关推荐

    springboot框架+thymeleaf模板引擎+layui前端框架+数据库

    "Thymeleaf模板引擎"允许开发者在模板中使用自然的HTML语法,通过添加特定的属性来实现动态内容的生成。这极大地提高了前端开发的效率和代码的可读性。 Layui是一个轻量级的前端UI框架,它的特点是模块化、响应式、...

    SpringBoot框架整合thymeleaf模板和mybatis

    然后,我们可以创建Thymeleaf模板文件,使用Thymeleaf语法来绑定数据和控制逻辑。对于MyBatis,我们需要定义Mapper接口和对应的XML文件,编写SQL语句,并在Service层中通过@Autowired注解注入Mapper实例进行数据库...

    springboot整合thymeleaf模板

    SpringBoot整合Thymeleaf模板是一项常见的Web开发任务,它结合了SpringBoot的便捷性和Thymeleaf的动态模板引擎,使得开发人员可以快速构建功能丰富的Web应用。下面将详细介绍这个过程及其涉及的关键知识点。 首先,...

    Springboot怎么集成Thymeleaf模板引擎?

    6. 在模板文件中使用 Thymeleaf 语法:Thymeleaf 提供了多种标准表达式,可以在模板文件中使用,例如 ${...} 变量表达式,*{...} 选择变量表达式等。 Thymeleaf 语法表达式有以下几种: * ${...}:变量表达式,...

    SpringBoot中整合Thymeleaf示例代码

    - 在模板中使用`#{message.key}`引用对应的消息。 通过上述步骤,你可以在Spring Boot应用中有效地整合Thymeleaf,实现高效且易于维护的前后端数据交互。在`helloSpringBoot2`这个项目中,你可以找到具体的代码...

    SpringBoot加Thymeleaf模板

    SpringBoot与Thymeleaf模板的整合是现代Java Web开发中的常见实践,它极大地简化了前端展示和后端逻辑的交互。SpringBoot以其简洁的配置和开箱即用的特性深受开发者喜爱,而Thymeleaf则是一款强大的服务器端模板引擎...

    springboot2.7.15+thymeleaf 代码

    在这个项目中,“基础使用”可能涵盖了SpringBoot的启动配置、Thymeleaf模板的创建、MVC模式的理解和实践、数据库连接配置等基本概念。开发者需要理解如何在SpringBoot的主配置文件(application.properties或...

    springboot2.0-thymeleaf.rar

    总结起来,这个"springboot2.0-thymeleaf.rar"项目是一个关于如何在SpringBoot 2.0中使用Thymeleaf进行Web开发的实例。通过学习这个项目,你可以掌握Thymeleaf的基本用法,以及如何在SpringBoot中配置和运行...

    SpringBoot中使用Thymeleaf的常用功能代码

    其核心特点是在静态模板中使用表达式,这些表达式在运行时会被替换为实际值,从而生成动态内容。Thymeleaf与Spring Boot的结合,使得我们可以利用Thymeleaf的强大功能,如条件语句、循环、国际化、表单处理等,轻松...

    浅析SpringBoot中使用thymeleaf找不到.HTML文件的原因

    在使用Thymeleaf时,需要在pom.xml文件中添加相应的依赖项,否则Spring Boot无法找到Thymeleaf模板引擎。pom.xml文件中添加以下依赖项: ```xml &lt;groupId&gt;org.springframework.boot &lt;artifactId&gt;spring-boot-...

    springboot如何使用thymeleaf模板访问html页面

    Spring Boot的`spring-boot-starter-web`依赖提供了基本的Web支持,而`spring-boot-starter-thymeleaf`则包含了Thymeleaf模板引擎: ```xml &lt;groupId&gt;org.springframework.boot &lt;artifactId&gt;spring-boot-...

    springboot用thymeleaf模板引擎

    SpringBoot与Thymeleaf模板引擎的整合是现代Java Web开发中的常见实践,它为开发者提供了便捷的MVC(Model-View-Controller)框架支持,实现了动态HTML页面的渲染。Thymeleaf是一款强大的服务器端模板引擎,尤其适用...

    Springboot整合Hibernate thymeleaf,添删改查,分页查询等,单元测试,亲测百分之白可运行

    6. 设计Thymeleaf模板:创建HTML模板,使用Thymeleaf语法进行条件判断、循环等操作。 7. 控制器层:创建Controller类,处理HTTP请求,调用Service层方法,并返回Thymeleaf模板。 对于添删改查和分页查询,...

    SpringBoot使用thymeleaf模板过程解析

    3. 创建实体类可以存储数据,以便在Thymeleaf模板中使用。 4. Thymeleaf模板可以使用模型对象来存储数据,以便在页面中展示数据。 5. 使用Thymeleaf模板可以简化Web应用程序的开发,提高开发效率。 6. SpringBoot...

    Spring Boot集成Thymeleaf模板引擎的完整步骤

    本文将为大家介绍Spring Boot集成Thymeleaf模板引擎的完整步骤,从基本概念到实际配置,详细地介绍了Thymeleaf模板引擎的使用方法。 一、Thymeleaf模板引擎概述 Thymeleaf是一种模板引擎框架,支持HTML5标准,可以...

    一个基于SpringBoot+Thymeleaf渲染的图书管理系统

    Thymeleaf表达式语言(Thymeleaf Expression Language, TEL)与Spring EL(Spring Expression Language)结合,可以在模板中直接引用模型数据。 4. RESTful API设计:SpringBoot支持RESTful风格的Web服务,可以通过...

    springboot+thymeleaf+maven+html+css实现精美大方好看官网模板完整源码.zip

    springboot+thymeleaf+maven+html+css实现精美大方好看官网模板完整源码 不需要搭建数据库即可启动,如果需要后台管理+数据库可以自己迭代拓展增加; 项目可以轻易修改,非常简单,非常适合新手

    blog系统,博客系统,后台springboot,前台thymeleaf,mysql.zip

    thymeleaf模板引擎 Semantic Ui shiro docker 错误 1.一些小伙伴在用我的代码时跑不起来,有些pojo类中的基础方法爆红,是因为没有安装lombok插件。。这是我的偷懒,不好意思,安装上应该就不会爆红了 2.解决了...

    springboot+thymeleaf可运行的案例

    通过阅读源码,你可以了解如何配置SpringBoot以加载Thymeleaf模板,以及如何在控制器中处理请求并返回视图。同时,Thymeleaf模板的使用将让你掌握如何在前端展示动态数据。如果你对任何部分有疑问,记得查看`t.txt`...

    springboot 自带模板thymeleaf 写的超市管理系统 带数据库 小白学习专用

    标题中的“SpringBoot自带模板Thymeleaf写的超市管理系统”是一个基于SpringBoot框架,并结合Thymeleaf模板引擎实现的简单超市管理应用。这个系统旨在帮助初学者理解如何在SpringBoot环境中集成Thymeleaf进行Web开发...

Global site tag (gtag.js) - Google Analytics