springboot thymeleaf返回带参数的页面

一、实现步骤

(1)依赖
<dependency> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
(2)控制层
@RequestMapping(value = "/test6", method = RequestMethod.GET) public String
test(Model model) throws Exception { model.addAttribute("name", "hahahahah");
model.addAttribute("currentDate", new Date()); return "list"; }
(3)页面

——springboot约定大于配置,资源文件默认存在resources/templates下

——前段页面需要满足thymeleaf的语法
<!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head> <meta
charset="UTF-8" /> <title>test</title> </head> <style> table td.td1{
width:191px; text-align:left; padding-left:20px; } table td.td2{ width:332px;
text-align:left; padding-left:20px; } table tr{ height:48px; font-family:
PingFangSC-Medium; font-size: 14px; color: rgba(0,0,0,0.80); line-height: 48px;
} table tr.topic{ font-family: PingFangSC-Semibold; font-size: 20px; color:
#FFFFFF; line-height: 20px; } table td.header{ height:48px; font-family:
PingFangSC-Medium; font-size: 14px; color: rgba(0,0,0,0.40); line-height: 48px;
text-align:left; padding-left:20px; } table tr:nth-child(even) { background:
#F7F7F7; } table th{ text-align:left; padding-left:20px; font-family:
PingFangSC-Medium; font-size: 14px; color: rgba(0,0,0,0.80); } </style> <body>
<div align="center"> <span th:text="${currentDate}"></span> <span
th:text="${name}"></span> </div> </body> </html>
(4)测试实现


友情链接
KaDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:637538335
关注微信