springboot——thymeleaf返回带参数的页面

springboot thymeleaf返回带参数的页面html

1、实现步骤spring

(1)依赖springboot

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

(2)控制层app

@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)页面spring-boot

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

——前段页面须要知足thymeleaf的语法spa

<!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)测试实现code