thymeleaf 创建/定义新变量

编程教程 (16) 2025-03-24 20:47:58

某些情况需要在thymeleaf 模板文件中定义变量,使用参考

 

定义单个参数:

<!doctype html>
<html lang="zh" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<body th:with="myvar=1">
	<!--使用变量-->
	<span th:text = "${myvar}">
</body>

定义多个参数:

<!doctype html>
<html lang="zh" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<body th:with="myvar=1,myvar2=${param.gid}">
	<!--使用变量-->
	<span th:text = "${myvar}">
	<span th:text = "${myvar2}">
</body>

注意:这里使用的是th:with  非  th:width !!!!

param.gid 为获取url地址中的gid参数,如果没有则是空

 

 


评论
User Image
提示:请评论与当前内容相关的回复,广告、推广或无关内容将被删除。

相关文章
某些情况需要在thymeleaf 模板文件中定义变量,使用参考 定义单个参数:&lt;!doctype html&gtl;&lt;html lang="zh" xmlns="htt
SSH/SSM项目中如何集成thymeleaf?本文将讲解SSH/SSM项目中如何集成thymeleaf模板引擎
Thymeleaf 递归,Thymeleaf模板引擎递归展示如评论留言等场合适用
使用thymeleaf 模板创建时间 使用thymeleaf 创建指定日期为:2023-10-18 #dates.create(2023,10,18) 使用thymeleaf ...
thymeleaf 设置不校验html标签
本文说一下在thymeleaf模板引擎中,如何给 textarea 赋值
thymeleaf模板 报错信息:​​​​​​​org.thymeleaf.exceptions.TemplateInputException: Error resolving template...
环境Thymeleaf 3.0循环5次需求:输出5个li编码参考:&lt;ul&gtl; &lt;li th:each="index:${#numbers.sequence(1,
springboot 使用thymeleaf 模板引擎中url中的&引起的org.xml.sax.SAXParseException: 对实体 "uid" 的引用必须以 ';' 分隔符结尾。问题解决
设置数据源将数据写入到 Model 中 @RequestMapping("/menulist") public String MenuManagerList(M
前言创建一个常规的web项目肯定需要一个模板引擎来实现,引用之前的项目《Vert.x 4 Web应用初识》基础结构目前vert.x支持多款模板引擎,包括:MVE
定义变量Shell 支持以下三种定义变量的方式:variable=value variable='value' variable="value"variable 是变量名,value 是赋给...
一、项目环境Spring Boot 2.1.2.RELEASEshiro-spring 1.4二、去掉URL jsessionid在shiro配置中,配置关闭url中显示sessionId ...
Postman 请求前修改密码为MD5值Postman请求参数设置 选择Pre-request Script栏目 获取明文密码并md5加密后设置到变量中 脚本://获取明文密码 let pwd...