首页 > 其他分享 >25-springboot-thymeleaf的常见属性

25-springboot-thymeleaf的常见属性

时间:2023-04-03 16:12:27浏览次数:42  
标签:25 springboot value thymeleaf user th inline 内联 文本

th:action

<form id="login" th:action="@{/login}">......</form>

th:method

<form id="login" th:action="@{/login}" th:method="post">......</form>

th:href

<a  class="login" th:href="@{/login}">登录</a>

th:id

<span th:id="${msg}">aaa</span>

<input id="nick" name="nick">

th:name

<input th:type="text" th:id="phone" th:name="phone">

th:value

<input type="hidden" id="userId" name="userId" th:value="${user.id}">

th:attr

<input type="hidden" id="userId" name="userId" th:attr="value=${userId}" >

th:text 用于文本的显示

<input type="text" id="realName" name="reaName" th:text="${realName}">

th:onclick

th:onclick="'getCollect()'"

th:style

th:style="'display:none;'"

th:if

条件判断,比如后台传来一个变量,判断该变量的值,1为男,2为女:

<span th:if="${sex} == 1" >

<input type="radio" name="se"  th:value="nan" />

</span>

<span th:if="${sex} == 2">

<input type="radio" name="se" th:value="nv"  />

</span>

th:unless

th:unless是th:if的一个相反操作:

<span th:unless="${sex} == 1" >

<input type="radio" name="se"  th:value="nv" />

</span>

<span th:unless="${sex} == 2">

<input type="radio" name="se" th:value="nan"  />

</span>

th:src

常与@{}表达式结合使用;

<script th:src="@{/js/jquery.min.js}"></script>

<img th:src="@{/image/beijing.gif}"/>

th:each

这个属性非常常用,用于对集合进行遍历输出,它与JSTL中的<c: forEach>类似;

<tr th:each="user, interStat : ${userList}">

    <td th:text="${interStat.index}"></td>

    <td th:text="${user.id}"></td>

    <td th:text="${user.nick}"></td>

    <td th:text="${user.phone}"></td>

    <td th:text="${user.email}"></td>

    <td th:text="${user.address}"></td>

</tr>

Map类型的循环:  

<div th:each="myMapVal : ${myMap}">

    <span th:text="${myMapVal.key}"></span>

    <span th:text="${myMapVal.value}"></span>

</div>

${myMapVal.key} 是获取map中的key,${myMapVal.value} 是获取map中的value;

数组类型的循环:  

<div th:each="myArrayVal : ${myArray}">

    <div th:text="${myArrayVal}"></div>

</div>

th:inline

内联文本、内联脚本

th:inline 有三个取值类型 (text, javascript 和 none)

该属性使用内联表达式[[…]]展示变量数据,比如:

内联文本

<span th:inline="text">

    Hello, [[${user.nick}]]

</span>

等同于:

<span>

    Hello, <span th:text="${user.nick}"></span>

</span>

th:inline写在任何父标签都可以,比如如下也是可以的:

<body th:inline="text">

   ...

   <span>[[${user.nick}]]</span>

   ...

</body>

使用场景:如果你不想依赖html标签就能进行动态数据展示,那么可以使用内联文本;

内联脚本

<script th:inline="javascript" type="text/javascript">

    var user = [[${user.phone}]];

    alert(user);

</script>

使用场景:如果你需要在javascript代码中获取动态数据,那么就需要使用内联脚本;

标签:25,springboot,value,thymeleaf,user,th,inline,内联,文本
From: https://www.cnblogs.com/healthinfo/p/17283364.html

相关文章

  • 展会倒计时,4.25日QME青岛国际机床展,台湾高技精彩继续!
    2023年4月25-28日,已进入倒计时21天,QME青岛国际机床展在将青岛世界博览城隆重举行,台湾高技在受邀行列当中!本届以6万平方米超大规模,700+全球供应商数量,预计达到6万观众数量。聚焦青岛制造业发展,集结全国乃至国际机床设备新技术与装备,共同打造行业专业交流、一站式装备集中采购交易......
  • 22-springboot应用监控-actuator
    可以做成页面监控(springboot-admin),而不是json的格式,看起来会更方便。在生产环境中,有时可能需要监控服务的可用性,spring-boot的actuator就是提供了对应用的配置查看、健康检查、相关功能统计等,可以通过HTTP,JMX来访问这些监控功能;(端点)如何使用该功能呢?1、在项目的Maven中添......
  • 【DP】LeetCode 256. 粉刷房子
    题目链接256.粉刷房子假如有一排房子,共n个,每个房子可以被粉刷成红色、蓝色或者绿色这三种颜色中的一种,你需要粉刷所有的房子并且使其相邻的两个房子颜色不能相同。当然,因为市场上不同颜色油漆的价格不同,所以房子粉刷成不同颜色的花费成本也是不同的。每个房子粉刷成不同颜......
  • day17| 110.平衡二叉树;257.二叉树的所有路径;404.左叶子之和
    110.平衡二叉树 自顶向下递归 1.获得计算二叉树高度的函数2.对于遍历到的节点,首先计算左右子树的高度,看是否平衡3.在分别遍历到左右子树,判断左子树和右子树是否平衡 代码如下:classSolution:defisBalanced(self,root:TreeNode)->bool:defhei......
  • SpringBoot集成Activiti7-单独配置数据源
    框架:SpringBoot+Mybatis+Activiti7思路:单独给mybatis和activiti配置datasourceMybati配置单数据源方法单数据源只需要在yml中配置url:jdbc:mysql://localhost:3306/localtest?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&rewriteBatchedStatemen......
  • SpringBoot 服务接口限流-AOP令牌桶
    前言在开发高并发系统时有三把利器用来保护系统:缓存、降级和限流。限流可以认为服务降级的一种,限流通过限制请求的流量以达到保护系统的目的。一般来说,系统的吞吐量是可以计算出一个阈值的,为了保证系统的稳定运行,一旦达到这个阈值,就需要限制流量并采取一些措施以完成限制流量的目的......
  • Springboot 系列 (27) - Springboot+HBase 大数据存储(五)| HBase REST 服务
    REST(RepresentationalStateTransfer)即表述性状态传递,是RoyFielding博士2000年在他的博士论文中提出来的一种软件架构风格。它是一种针对网络应用的设计和开发方式,可以降低开发的复杂性,提高系统的可伸缩性。在三种主流的Web服务实现方案中,与复杂的SOAP和XML-RPC相......
  • springboot集成mybatis-plus
    springboot项目先导入相关依赖mybatis-plus相关依赖<dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.0.5</version></dependency><dependency><gr......
  • 2516. 每种字符至少取 K 个
    力扣题目链接给你一个由字符 'a'、'b'、'c' 组成的字符串 s 和一个非负整数 k 。每分钟,你可以选择取走 s 最左侧 还是 最右侧 的那个字符。你必须取走每种字符 至少 k 个,返回需要的 最少 分钟数;如果无法取到,则返回 -1 。 示例1:输入:s="aabaaaacaabc",k......
  • springboot起步依赖
    <parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.0.0.RELEASE</version><relativePath/><!--lookupparentfromrepository--></......