当前位置:网站首页>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 call the function mode of one hand and one machine
- C - Divisors of the Divisors of An Integer Gym - 102040C
- openGauss数据库源码解析系列文章—— 密态等值查询技术详解(下)
- VC development of non MFC program memory leak tracking code
- Scenario based technology architecture process based on tidb - Theory
- mysql 自定义函数 身份证号转年龄(支持15/18位身份证)
- Sorter evolution of ticdc 6.0 principle
- R语言ggplot2可视化密度图:按照分组可视化密度图、自定义配置geom_density函数中的alpha参数设置图像透明度(防止多条密度曲线互相遮挡)
- 清大科越冲刺科创板:年营收2亿 拟募资7.5亿
- 3W principle [easy to understand]
猜你喜欢

Scenario based technology architecture process based on tidb - Theory

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

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

Qingda KeYue rushes to the science and Innovation Board: the annual revenue is 200million, and it is proposed to raise 750million

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

How to introduce devsecops into enterprises?

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

金融壹账通香港上市:市值63亿港元 叶望春称守正笃实,久久为功

Sharing the 12 most commonly used regular expressions can solve most of your problems

What are the advantages and characteristics of SAS interface
随机推荐
R语言使用nnet包的multinom函数构建无序多分类logistic回归模型、使用coef函数获取模型中每个变量(自变量改变一个单位)对应的对数优势比(log odds ratio)
总量分析 核算方法和势方法 - 分摊分析
Lepton 无损压缩原理及性能分析
故障分析 | MySQL 耗尽主机内存一例分析
Why do I support bat to dismantle "AI research institute"
金融壹賬通香港上市:市值63億港元 葉望春稱守正篤實,久久為功
TiFlash 源码解读(四) | TiFlash DDL 模块设计及实现分析
Laravel - view (new and output views)
Sharing the 12 most commonly used regular expressions can solve most of your problems
R语言dplyr包select函数、group_by函数、mutate函数、cumsum函数计算dataframe分组数据中指定数值变量的累加值、并生成累加数据列
Shenziyu, the new chairman of Meizu: Mr. Huang Zhang, the founder, will serve as the strategic adviser of Meizu's scientific and technological products
魅族新任董事長沈子瑜:創始人黃章先生將作為魅族科技產品戰略顧問
R语言ggplot2可视化:可视化折线图、使用theme函数中的legend.position参数自定义图例的位置
Qingda KeYue rushes to the science and Innovation Board: the annual revenue is 200million, and it is proposed to raise 750million
2022 construction welder (special type of construction work) special operation certificate examination question bank and online simulation examination
R language ggplot2 visualization: gganimate package is based on Transition_ The time function creates dynamic scatter animation (GIF) and uses shadow_ Mark function adds static scatter diagram as anim
3W原则[通俗易懂]
Google eventbus usage details
分享 20 个稀奇古怪的 JS 表达式,看看你能答对多少
LeetCode_3(无重复字符的最长子串)