Thymeleaf是什么?

Thymeleaf是适用于Web和独立环境的现代服务器端Java模板引擎。相比于JSPThymeleaf更简洁,渲染性能更好,维护性更好它可以XML/XHTML/HTML5 JavaScript, CSS ,甚至文本文件,避免了JSP页面代码与Java代码混合的情况,更有利于前后端分离,使用Thymeleaf可以实现spring-boot的诸多特性

Demo建立:

 

打开IDEAFile->New Project,选择Spring Initializr

Thymeleaf学习记录(1)--启动模板及建立Demo

 

下一步

Thymeleaf学习记录(1)--启动模板及建立Demo

下一步

选中Web

Thymeleaf学习记录(1)--启动模板及建立Demo

然后点击完成,文件结构如下:

Thymeleaf学习记录(1)--启动模板及建立Demo

添加Controller,再com.example.demo下右键,添加class

Thymeleaf学习记录(1)--启动模板及建立Demo

HelloController内容如下:

Thymeleaf学习记录(1)--启动模板及建立Demo

测试Demo,点击DemoAppcation->右键,run DemoAppcation 启动项目,输出如下启动成功:

Thymeleaf学习记录(1)--启动模板及建立Demo

打开浏览器:输入localhost:8080/Hello/Say显示如下成功。

Thymeleaf学习记录(1)--启动模板及建立Demo

接下里配置和Thymeleaf页面:

再pom.xml文件添加如下内容

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

然后导入包,如下所示:

 Thymeleaf学习记录(1)--启动模板及建立Demo

 

在templates中新建HTML File

 

Thymeleaf学习记录(1)--启动模板及建立Demo

输入HTML内容:

Thymeleaf学习记录(1)--启动模板及建立Demo

添加Controller映射:

Thymeleaf学习记录(1)--启动模板及建立Demo

启动项目,访问http://localhost:8080/Hello/GetPage,出现如下页面,成功!

Thymeleaf学习记录(1)--启动模板及建立Demo

 

 

 

 

 

 

 

相关文章:

  • 2022-12-23
  • 2021-06-05
  • 2021-07-14
  • 2021-11-13
  • 2021-04-18
  • 2021-10-13
  • 2022-12-23
  • 2021-11-19
猜你喜欢
  • 2021-09-12
  • 2021-12-15
  • 2022-12-23
  • 2021-08-25
  • 2021-06-29
  • 2022-01-15
  • 2022-12-23
相关资源
相似解决方案