当前位置:网站首页>Thymeleaf th:classappend属性追加 th:styleappend样式追加 th:data-自定义属性
Thymeleaf th:classappend属性追加 th:styleappend样式追加 th:data-自定义属性
2022-07-05 14:10:00 【fengyehongWorld】
后台数据准备
public ZTestEntity init3() {
ZTestEntity zTestEntity = new ZTestEntity();
zTestEntity.setIsAdmin(true);
zTestEntity.setName("贾飞天");
return zTestEntity;
}
// ------------------------------------------------
@GetMapping("/init3")
public ModelAndView init3() {
ModelAndView modelAndView = new ModelAndView();
ZTestEntity entity = service.init3();
modelAndView.addObject("entity", entity);
modelAndView.setViewName("test3");
return modelAndView;
}
前台
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<style> .content {
color: red; } .preAttr {
margin-top: 10px; } .test3 {
border: 1px solid yellow; } </style>
<title>test3页面的标题</title>
</head>
<body>
<div id="container" th:object="${entity}">
<!-- // 省略...... -->
</div>
</body>
</html>
一. th:classappend
<!-- 当isAdmin为true时,追加test3属性;否则不执行任何操作 -->
<div class="content" th:classappend="*{isAdmin} ? test3 : _">th:classappend测试内容</div>
渲染后
二. th:styleappend
<!-- 当isAdmin为true时,追加 margin-top:50px 的样式;否则什么都不做 -->
<div style="color: pink;" th:styleappend="*{isAdmin} ? 'margin-top:50px' : _">th:styleappend测试内容</div>
渲染后
三. 自定义属性
<!-- data- 自定义属性可以直接通过 th: 的形式来追加 -->
<div th:data-custom-name="*{name}">th:data-属性测试内容</div>
<!-- th:任意属性名 的方式,可以添加任意属性 -->
<div th:haha="*{name}">th:任意属性测试内容</div>
<hr>
渲染后
四. data-th-属性名的写法
<!-- data-th-属性名 和 th:属性名作用相同,只不过是写法不同 -->
<div data-th-class="*{name}">data-th-测试内容</div>
<div th:class="*{name}">th:class测试内容</div>
渲染后
边栏推荐
- VC development of non MFC program memory leak tracking code
- 根据CronSequenceGenerator计算cron表达式的时间
- Laravel dompdf exports PDF, and the problem of Chinese garbled code is solved
- VC开发非MFC程序内存泄漏跟踪代码
- R语言ggplot2可视化:gganimate包基于transition_time函数创建动态散点图动画(gif)、使用shadow_mark函数为动画添加静态散点图作为动画背景
- 动态规划
- LeetCode_2(两数相加)
- Sharing the 12 most commonly used regular expressions can solve most of your problems
- 世界环境日 | 周大福用心服务推动减碳环保
- Judge whether the variable is an array
猜你喜欢

How to deeply understand the design idea of "finite state machine"?

Mingfeng medical sprint technology innovation board: annual revenue of 350million yuan, proposed to raise 624million yuan

软件测试人在深圳有哪些值得去的互联网公司【软件测试人员专供版】

清大科越冲刺科创板:年营收2亿 拟募资7.5亿

非技术部门,如何参与 DevOps?

神经网络物联网未来发展趋势怎么样

无密码身份验证如何保障用户隐私安全?

TiFlash 面向编译器的自动向量化加速

Postman简介、安装、入门使用方法详细攻略!

Getting started with rce
随机推荐
-Web direction attack and defense world
分享 12 个最常用的正则表达式,能解决你大部分问题
无密码身份验证如何保障用户隐私安全?
最长公共子序列 - 动态规划
Postman简介、安装、入门使用方法详细攻略!
Qingda KeYue rushes to the science and Innovation Board: the annual revenue is 200million, and it is proposed to raise 750million
Introduction, installation, introduction and detailed introduction to postman!
TiFlash 源码解读(四) | TiFlash DDL 模块设计及实现分析
Implementation process of WSDL and soap calls under PHP5
Detailed explanation of IP address and preparation of DOS basic commands and batch processing
一网打尽异步神器CompletableFuture
R language ggplot2 visual density map: Visual density map by group and custom configuration geom_ The alpha parameter in the density function sets the image transparency (to prevent multiple density c
How to make a second clip of our media video without infringement
让秒杀狂欢更从容:大促背后的数据库(下篇)
神经网络物联网未来发展趋势怎么样
做自媒体视频二次剪辑,怎样剪辑不算侵权
3W原则[通俗易懂]
The forked VM terminated without saying properly goodbye
R语言使用MASS包的polr函数构建有序多分类logistic回归模型、使用coef函数获取模型中每个变量(自变量改变一个单位)对应的对数优势比(log odds ratio)
R Language ggplot2 Visualization: visualize linegraph, using Legend in Theme function. Paramètre de position emplacement de la légende personnalisée