首页 > 其他分享 >12_SpringBoot_整合Thymeleaf_掌握

12_SpringBoot_整合Thymeleaf_掌握

时间:2023-03-20 23:35:24浏览次数:36  
标签:12 SpringBoot spring boot springframework Thymeleaf org starter

 

12_SpringBoot_整合Thymeleaf_掌握_HTML

   Thymeleaf的主要目标是将优雅的自然模板带到开发工作流程中,并将HTML在浏览器中正确显示,并且可以作为静态原型,让开发团队能更容易地协作。Thymeleaf能够处理HTML,XML,JavaScript,CSS甚至纯文本。
    长期以来,jsp在视图领域有非常重要的地位,随着时间的变迁,出现了一位新的挑战者:Thymeleaf,Thymeleaf是原生的,不依赖于标签库.它能够在接受原始HTML的地方进行编辑和渲染.因为它没有与Servelet规范耦合,因此Thymeleaf模板能进入jsp所无法涉足的领域。
    Thymeleaf在Spring Boot项目中放入到resources/templates中。这个文件夹中的内容是无法通过浏览器URL直接访问的(和WEB-INF效果一样),所有Thymeleaf页面必须先走控制器。

创建项目,准备配置文件及各层级代码

项目中添加依赖

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.21</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.12</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.10</version>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.12</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>2.4.5</version>
</dependency>
</dependencies>

12_SpringBoot_整合Thymeleaf_掌握_spring_02

12_SpringBoot_整合Thymeleaf_掌握_spring_03

 

关于Thymeleaf默认配置

12_SpringBoot_整合Thymeleaf_掌握_ci_04

12_SpringBoot_整合Thymeleaf_掌握_ci_05

 

在resources下新建templates文件夹。新建index.html

新建控制器

 

package com.msb.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
/**
* @Author: Ma HaiYang
* @Description: MircoMessage:Mark_7001
*/
@Controller
public class ThymeleafController {
@RequestMapping("showIndex")
public String showIndex(){
return "index";
}
}

12_SpringBoot_整合Thymeleaf_掌握_spring_06

12_SpringBoot_整合Thymeleaf_掌握_ci_07

 

启动项目测试即可

12_SpringBoot_整合Thymeleaf_掌握_spring_08

 


标签:12,SpringBoot,spring,boot,springframework,Thymeleaf,org,starter
From: https://blog.51cto.com/u_15975228/6138666

相关文章

  • 15_SpringBoot_模板引擎总结_了解
    jsp优点:1、功能强大,可以写java代码2、支持jsp标签(jsptag)3、支持表达式语言(el)4、官方标准,用户群广,丰富的第三方jsp标签库缺点:性能问题。不支持前后端分离freemarker......
  • 15_SpringBoot_模板引擎总结_了解
    jsp优点:1、功能强大,可以写java代码2、支持jsp标签(jsptag)3、支持表达式语言(el)4、官方标准,用户群广,丰富的第三方jsp标签库缺点:性能问题。不支持前后端分离freemarker......
  • VirtualBox 5.1.12发布支持Linux Kernel 4.10
    甲骨文(Oracle)近日宣布了VirtualBox5.1稳定版分支最新维护版本更新,带来了大量有价值的BUG修复和系统改善。VirtualBox5.1.12尤其为​​Linux​​用户新增了大量内容,除了支......
  • 16_SpringBoot_开发者工具_了解
     使用开发者工具包不需要重启。监听内容改变。1导入依赖 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-d......
  • 16_SpringBoot_开发者工具_了解
     使用开发者工具包不需要重启。监听内容改变。1导入依赖 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-d......
  • SpringBoot-jar和war方式打包部署项目
    携手创作,共同成长!这是我参与「掘金日新计划·8月更文挑战」的第30天,点击查看活动详情SpringBoot项目开发完成后,需要以jar或war的方式将项目打包部署到测试开发环境。......
  • VirtualBox 5.1.12发布支持Linux Kernel 4.10
    甲骨文(Oracle)近日宣布了VirtualBox5.1稳定版分支最新维护版本更新,带来了大量有价值的BUG修复和系统改善。VirtualBox5.1.12尤其为​​Linux​​用户新增了大量内容,除了支......
  • VirtualBox 5.1.12发布支持Linux Kernel 4.10
    甲骨文(Oracle)近日宣布了VirtualBox5.1稳定版分支最新维护版本更新,带来了大量有价值的BUG修复和系统改善。VirtualBox5.1.12尤其为Linux用户新增了大量内容,除了支持即......
  • 16_SpringBoot_开发者工具_了解
    ​ 使用开发者工具包不需要重启。监听内容改变。1导入依赖 <dependency><groupId>org.springframework.boot</groupId><artifact......
  • 16_SpringBoot_开发者工具_了解
    ​ 使用开发者工具包不需要重启。监听内容改变。1导入依赖 <dependency><groupId>org.springframework.boot</groupId><artifact......