当前位置:网站首页>Thymeleaf Usage Summary
Thymeleaf Usage Summary
2022-06-25 14:27:00 【Enlightened gentleman】
1、 Output text
<div th:text="${user.age}"></div>2、 Output html
<div th:utext="${user.name}"></div>3、 Output to a In tag properties
userid Is the value of the background setting
<a th:href="@{/user/detail/{id}(id=${userid})}"></a>4、 Traverse list
<a th:each="u : ${userList}">
<p>
<span th:text="${u.name}"></span>
<span th:text="${u.age}"></span>
</p>
</a>Code testing
Use here springboot project
Definition User Entity class
package com.learn.bean;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* User
*
* @author wsjz
* @date 2021/07/15
*/
@NoArgsConstructor
@AllArgsConstructor
@Data
public class User {
private String id;
private String name;
private Integer age;
}
Definition controller
package com.learn.controller;
import com.learn.bean.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import java.util.ArrayList;
import java.util.List;
/**
* DemoController
*
* @author wsjz
* @date 2021/07/15
*/
@Controller
public class IndexController {
@RequestMapping("/")
public ModelAndView index() {
ModelAndView mav = new ModelAndView();
mav.addObject("userList", userList());
mav.addObject("user", user());
mav.setViewName("index");
return mav;
}
private List<User> userList() {
List<User> userList = new ArrayList<>();
User user1 = new User("1", " Jia Yuanchun ", 18);
User user2 = new User("2", " Jia Yingchun ", 17);
User user3 = new User("3", " Jia Tanchun ", 16);
User user4 = new User("4", " Jia Xichun ", 15);
userList.add(user1);
userList.add(user2);
userList.add(user3);
userList.add(user4);
return userList;
}
private User user() {
User user = new User("5", "<p style='color:red'> Jia Baoyu <p>", 16);
return user;
}
}
thymeleaf page
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<a th:href="@{/user/detail/{id}(id=${u.id})}" th:each="u : ${userList}">
<p>
<span th:text="${u.name}"></span>
<span th:text="${u.age}"></span>
</p>
</a>
<hr>
<div th:utext="${user.name}"></div>
<div th:text="${user.age}"></div>
</body>
</html>Running effect

That's it
边栏推荐
- 英语中的九大词性与九大时态
- Complete and detailed compilation of experimental reports
- 阻止深度神经网络过拟合(Mysteries of Neural Networks Part II)
- 使用调试工具调试博图TCP连接所遇到的问题
- JS Base64 Library Learning
- 关于STM32使用LAN8720A插拔网线重连
- 现在股票开户用什么app最安全?知道的给说一下吧
- Report on Hezhou air32f103cbt6 development board
- 测一测你的挣钱能力有多强?未来的你将从事什么职业?
- Let and const commands
猜你喜欢

英語中的九大詞性與九大時態

Numpy库使用入门

算力&NFT交易平台F3.xyz旗下独家权益NFT项目Hash Eagle将盛大发行

Experts' suggestions | 8 measures to accelerate your innovative career planning and growth

一次性讲清楚 Handler 可能导致的内存泄漏和解决办法 | 开发者说·DTalk

‘nvidia-smi‘ 不是内部或外部命令,也不是可运行的程序或批处理文件

Beego--- notes

Application of TSDB in civil aircraft industry

TSDB在民机行业中的应用

shell 变量 入门
随机推荐
JVM uses tools to analyze classic cases of OOM
Sigmoid function sigmoid derivation
【世界历史】第二集——文明的曙光
Getting started with numpy Library
Is qiniu regular? Is it safe to open a stock account?
It's not easy to understand the data consistency of the microservice architecture for the first time after six years as a programmer
Common formatting methods for amount numbers
Getting started with shell variables
两种方法实现pycharm中代码回滚到指定版本(附带截图展示)
None of the MLIR Optimization Passes are enabled (registered 2)解决办法
turtlebot+lms111+gmapping实践
Golang project dependency management tool go vendor, go Mod
哈希錶、哈希沖突
Deploy eve-ng with KVM virtualization
Network remote access using raspberry pie
Asp.net WebForm使用NPOI导出Excel
Basic usage of markdown (plain text and grammar)
Nine parts of speech and nine tenses in English
程序员为什么要软一点?
One time summary: 64 common terms for data analysis!