当前位置: 首页 > news >正文

第二节:如何使用thymeleaf渲染html(自学Spring boot 3.x的第一天)

大家好,我是网创有方,今天来学习如何使用thymeleaf渲染html。该模板运用不广泛,所以本节内容了解既可。

第一步:创建html文件。

在模板templates目录下创建一个html文件。

编写代码如下:

<!DOCTYPE html>
<html lang="en" xmlns:th="www.thymeleaf.org"/>
<head><meta charset="UTF-8"><title>thymeleaf演示</title>
</head>
<body>
<p th:text="${description}"/>thymeleaf
</body>
</html>

第二步:编写动态渲染属性值。

并返回渲染的html文件。

package cn.wcyf.wcai;import jakarta.servlet.http.HttpServletRequest;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;@SpringBootApplicationpublic class WcaiApplication {public static void main(String[] args) {SpringApplication.run(WcaiApplication.class, args);}@Controllerpublic static  class HelloController{@GetMapping("/test")public String test(HttpServletRequest request){//设置请求的属性request.setAttribute("description","你好啊 ");return "index";}}}

第三步:点击运行

接下来访问localhost:test

参考:《深入浅出spring-boot 3.x》

http://www.lryc.cn/news/389242.html

相关文章:

  • 计算机相关术语科普之什么叫网关(Gateway)
  • B站网页部分API
  • 使用Spring Boot和Spring Security保护你的应用
  • CVE-2019-12272 Openwrt可视页面LuCi命令注入漏洞复现(完结)
  • 【多线程开发 4】从源码学习LockSupport
  • gameui C++的代码
  • 1.什么是js?特点是什么?组成部分?
  • 爬虫是什么?
  • 深入理解Presto分页查询:方法与最佳实践
  • 如何使用Go语言中的并发函数实现网络爬虫的分布式部署?
  • STM32第九课:DHT11温湿度传感器
  • JVM线上监控环境搭建Grafana+Prometheus+Micrometer
  • MyBatis(17)MyBatis 如何处理枚举类型
  • 云数据中心运维新纪元:让Linux服务器如虎添翼
  • C# 多线程造成CPU占用率高
  • 谈谈在不同公司中的SAP职位
  • 服务器连接不上
  • 论文辅导 | 基于贝叶斯优化-卷积神经网络-双向长短期记忆神经网络的锂电池健康状态评估
  • 安卓实现微信聊天气泡
  • 软件测试(功能、接口、性能、自动化)详解 | 测试人生路
  • 【面试题】网络IO模型
  • 数据结构-----【链表:基础】
  • 如何在pycharm里面运行pytest用例
  • Charles抓包工具踩坑记录
  • 【RabbitMQ实战】邮件发送(直连交换机、手动ack)
  • python 笔试面试八股(自用版~)
  • 《SpringBoot+Vue》Chapter04 SpringBoot整合Web开发
  • 腾讯地图异步调用
  • 通过docker overlay2 目录名查找占用磁盘空间最大的容器名和容器ID
  • 每周算法:有向图强连通分量