当前位置:网站首页>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>
渲染后
边栏推荐
- How to introduce devsecops into enterprises?
- Scenario based technology architecture process based on tidb - Theory
- What category does the Internet of things application technology major belong to
- Sharing the 12 most commonly used regular expressions can solve most of your problems
- JS takes key and value from an array object to form a new object
- 矩阵链乘 - 动态规划实例
- Use the word "new" to attract curious people
- R language uses the multinom function of NNET package to build an unordered multi classification logistic regression model, and uses the coef function to obtain the log odds ratio corresponding to eac
- What are the advantages and characteristics of SAS interface
- R语言ggplot2可视化:使用ggplot2可视化散点图、使用labs参数自定义X轴的轴标签文本(customize X axis labels)
猜你喜欢

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

Getting started with rce

Zhizhen new energy rushes to the scientific innovation board: the annual revenue is 220million, and SAIC venture capital is the shareholder

Why do I support bat to dismantle "AI research institute"

LeetCode_ 2 (add two numbers)

tidb-dm报警DM_sync_process_exists_with_error排查

国富氢能冲刺科创板:拟募资20亿 应收账款3.6亿超营收

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

Financial one account Hong Kong listed: market value of 6.3 billion HK $Ye wangchun said to be Keeping true and true, long - term work

Redis如何实现多可用区?
随机推荐
Simple process of penetration test
Judge whether the variable is an array
魅族新任董事長沈子瑜:創始人黃章先生將作為魅族科技產品戰略顧問
关于memset赋值的探讨
Getting started with rce
The IPO of Ruineng industry was terminated: the annual revenue was 447million and it was planned to raise 376million
R语言ggplot2可视化条形图:通过双色渐变配色颜色主题可视化条形图、为每个条形添加标签文本(geom_text函数)
C - Divisors of the Divisors of An Integer Gym - 102040C
LeetCode_67(二进制求和)
R Language ggplot2 Visualization: visualize linegraph, using Legend in Theme function. Paramètre de position emplacement de la légende personnalisée
The speed monitoring chip based on Bernoulli principle can be used for natural gas pipeline leakage detection
明峰医疗冲刺科创板:年营收3.5亿元 拟募资6.24亿
VC development of non MFC program memory leak tracking code
用“新”字来吸引好奇的人群
04_solr7.3之solrJ7.3的使用
What is the ranking of GF futures? Is it safe and reliable to open an account for GF futures online?
Zhizhen new energy rushes to the scientific innovation board: the annual revenue is 220million, and SAIC venture capital is the shareholder
Discussion on memset assignment
01. Solr7.3.1 deployment and configuration of jetty under win10 platform
Assembly language