当前位置:网站首页>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>
渲染后
边栏推荐
- C - Divisors of the Divisors of An Integer Gym - 102040C
- 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
- Laravel - model (new model and use model)
- The forked VM terminated without saying properly goodbye
- Google eventbus usage details
- Current situation, trend and view of neural network Internet of things in the future
- How to call the function mode of one hand and one machine
- Linux下mysql数据库安装教程
- VC development of non MFC program memory leak tracking code
- 关于memset赋值的探讨
猜你喜欢

upload (1-6)

What are the advantages and characteristics of SAS interface

为什么我认识的机械工程师都抱怨工资低?

OSI and tcp/ip protocol cluster

Guofu hydrogen energy rushes to the scientific and Technological Innovation Board: it plans to raise 2billion yuan, and 360million yuan of accounts receivable exceed the revenue

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

分享 20 个稀奇古怪的 JS 表达式,看看你能答对多少

区间 - 左闭右开

Shenziyu, the new chairman of Meizu: Mr. Huang Zhang, the founder, will serve as the strategic adviser of Meizu's scientific and technological products

LeetCode_ 2 (add two numbers)
随机推荐
tidb-dm报警DM_sync_process_exists_with_error排查
R语言ggplot2可视化:gganimate包基于transition_time函数创建动态散点图动画(gif)、使用shadow_mark函数为动画添加静态散点图作为动画背景
Assembly language
别不服气。手机功能升级就是强
LeetCode_ 2 (add two numbers)
How to make a second clip of our media video without infringement
2022 machine fitter (Advanced) test question simulation test question bank simulation test platform operation
Google EventBus 使用详解
Mingfeng medical sprint technology innovation board: annual revenue of 350million yuan, proposed to raise 624million yuan
世界环境日 | 周大福用心服务推动减碳环保
为什么我认识的机械工程师都抱怨工资低?
Interpretation of tiflash source code (IV) | design and implementation analysis of tiflash DDL module
Detailed explanation of IP address and preparation of DOS basic commands and batch processing
MySQL user-defined function ID number to age (supports 15 / 18 digit ID card)
Hongmeng fourth training
What is the future development trend of neural network Internet of things
Use the word "new" to attract curious people
国富氢能冲刺科创板:拟募资20亿 应收账款3.6亿超营收
The speed monitoring chip based on Bernoulli principle can be used for natural gas pipeline leakage detection
Faire un clip vidéo auto - média deux fois, comment clip n'est pas considéré comme une infraction