当前位置:网站首页>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>
渲染后
边栏推荐
- Laravel - model (new model and use model)
- 2022 driller (drilling) examination question bank and simulation examination
- 做自媒体视频二次剪辑,怎样剪辑不算侵权
- ASP.NET大型外卖订餐系统源码 (PC版+手机版+商户版)
- Recommendation number | what are interesting people looking at?
- Make the seckill Carnival more leisurely: the database behind the promotion (Part 2)
- Google eventbus usage details
- LeetCode_ 67 (binary sum)
- Enjoy what you want. Zhichuang future
- R language dplyr package select function, group_ By function, mutate function and cumsum function calculate the cumulative value of the specified numerical variable in the dataframe grouping data and
猜你喜欢

Detailed explanation of IP address and preparation of DOS basic commands and batch processing

Tdengine biweekly selection of community issues | phase III

魅族新任董事長沈子瑜:創始人黃章先生將作為魅族科技產品戰略顧問

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

基于 TiDB 场景式技术架构过程 - 理论篇

Make the seckill Carnival more leisurely: the database behind the promotion (Part 2)
![Which Internet companies are worth going to in Shenzhen for software testers [Special Edition for software testers]](/img/c2/a5f5fe17a6bd1f6f9df828ddd224d6.png)
Which Internet companies are worth going to in Shenzhen for software testers [Special Edition for software testers]

金融壹賬通香港上市:市值63億港元 葉望春稱守正篤實,久久為功

Introduction, installation, introduction and detailed introduction to postman!

Brief introduction to revolutionary neural networks
随机推荐
Shen Ziyu, nouveau Président de Meizu: M. Huang Zhang, fondateur de Meizu, agira comme conseiller stratégique pour les produits scientifiques et technologiques de Meizu
04_ Use of solrj7.3 of solr7.3
LeetCode_ 69 (square root of x)
Introduction, installation, introduction and detailed introduction to postman!
VC开发非MFC程序内存泄漏跟踪代码
Sorter evolution of ticdc 6.0 principle
微服务项目部署后,无法访问静态资源,无法访问到上传到upload中的文件,解决办法
upload (1-6)
LeetCode_2(两数相加)
Simple process of penetration test
Hongmeng fourth training
Why do I support bat to dismantle "AI research institute"
How to introduce devsecops into enterprises?
R language ggplot2 visualization: visual line graph, using legend in theme function The position parameter defines the position of the legend
R language uses the polR function of mass package to build an ordered multi classification logistic regression model, and uses the coef function to obtain the log odds ratio corresponding to each vari
C - Divisors of the Divisors of An Integer Gym - 102040C
国富氢能冲刺科创板:拟募资20亿 应收账款3.6亿超营收
PHP5下WSDL,SOAP调用实现过程
分享 20 个稀奇古怪的 JS 表达式,看看你能答对多少
Zhizhen new energy rushes to the scientific innovation board: the annual revenue is 220million, and SAIC venture capital is the shareholder