发布时间:2024-01-23 17:00
创建springboot项目,导入Thymeleaf依赖
<dependency>
<groupId>org.springframework.bootgroupId>
<artifactId>spring-boot-starter-thymeleafartifactId>
dependency>
Controller
@Controller
public class TestController {
@RequestMapping("t1")
public String hello() {
return "test";
}
}
在resources下创建templates文件夹,在文件夹下新建test.html
DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Titletitle>
head>
<body>
<h1>测试页面h1>
body>
html>
启动项目,访问http://localhost:8080/t1
编写controller
@RequestMapping("/t1")
public String test1(Model model){
//存入数据
model.addAttribute("msg","Hello,Thymeleaf");
//classpath:/templates/test.html
return "test";
}
html页面
DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>标题title>
head>
<body>
<h1>测试页面h1>
<div th:text="${msg}">div>
body>
html>
启动测试:
再写一个controller
@RequestMapping("/t2")
public String test2(Map<String,Object> map){
//存入数据
map.put("msg","Hello
");
map.put("users", Arrays.asList("lisi","zhangsan"));
//classpath:/templates/test.html
return "test2";
}
创建一个新的test2.html
DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>标题title>
head>
<body>
<h1>测试页面h1>
<div th:text="${msg}">div>
<div th:utext="${msg}">div>
<h4 th:each="user :${users}" th:text="${user}">h4>
<h4>
<span th:each="user:${users}">[[${user}]]span>
h4>
body>
html>
启动项目,访问 http://localhost:8080/t2
喜讯!喜讯!JeecgBoot Github超 30000 Star—这个低代码平台你还不知道吗?
影响分析:RubyGems未授权访问漏洞(CVE-2022-29176)
源码安装LNMP架构,保姆级教程,从安装服务搭建到部署网站,超详细,全文步骤搭配操作解释
matlab求两个离散数据的相关性,matlab求两个序列的相关性_matlab求相关性_两个序列的相关性...
《Vue入门到精通》最强Vue教程,附带经典案例,万字详解,干货十足!
分布式和集群的理解和redis集群及jidis连接集群和Spring控制反转
BufferedWniter_字符缓冲输出流和BufferedReader_字符缓冲输入流