当前位置:网站首页>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>
渲染后
边栏推荐
- R语言使用MASS包的polr函数构建有序多分类logistic回归模型、使用coef函数获取模型中每个变量(自变量改变一个单位)对应的对数优势比(log odds ratio)
- OSI and tcp/ip protocol cluster
- 04_ Use of solrj7.3 of solr7.3
- 昆仑太科冲刺科创板:年营收1.3亿拟募资5亿 电科太极持股40%
- Detailed explanation of SSH password free login
- 01. Solr7.3.1 deployment and configuration of jetty under win10 platform
- LeetCode_67(二进制求和)
- Webrtc learning (II)
- 03_ Dataimport of Solr
- 世界环境日 | 周大福用心服务推动减碳环保
猜你喜欢

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

Introduction, installation, introduction and detailed introduction to postman!

Current situation, trend and view of neural network Internet of things in the future

OSI and tcp/ip protocol cluster

Tidb DM alarm DM_ sync_ process_ exists_ with_ Error troubleshooting

What category does the Internet of things application technology major belong to

Comparison of several distributed databases

TiCDC 6.0原理之Sorter演进

-Web direction attack and defense world

TDengine 社区问题双周精选 | 第三期
随机推荐
04_ Use of solrj7.3 of solr7.3
How to deeply understand the design idea of "finite state machine"?
IP packet header analysis and static routing
Leetcode array question brushing notes
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
享你所想。智创未来
mysql 自定义函数 身份证号转年龄(支持15/18位身份证)
做自媒體視頻二次剪輯,怎樣剪輯不算侵權
Hongmeng fourth training
分享 12 个最常用的正则表达式,能解决你大部分问题
一网打尽异步神器CompletableFuture
关于memset赋值的探讨
R语言ggplot2可视化密度图:按照分组可视化密度图、自定义配置geom_density函数中的alpha参数设置图像透明度(防止多条密度曲线互相遮挡)
Introduction, installation, introduction and detailed introduction to postman!
金融壹賬通香港上市:市值63億港元 葉望春稱守正篤實,久久為功
清大科越冲刺科创板:年营收2亿 拟募资7.5亿
The forked VM terminated without saying properly goodbye
昆仑太科冲刺科创板:年营收1.3亿拟募资5亿 电科太极持股40%
Tdengine biweekly selection of community issues | phase III
Laravel dompdf exports PDF, and the problem of Chinese garbled code is solved