标签:port lang pid 之一 rop 引入 pojo ret person
<properties> <!-- thymeleaf2 layout1--> <thymeleaf-layout-dialect.version>2.4.1</thymeleaf-layout-dialect.version>
</properties>
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
在html的头中引入:
<html lang="en" xmlns:th="http://www.thymeleaf.org">
controller:
package com.org.controller; import com.org.pojo.dog; import com.org.pojo.person; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import javax.servlet.http.HttpServletRequest; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; @Controller public class thymeleafController { @RequestMapping("testyh") public String testyh(HttpServletRequest request){ request.setAttribute("name","admin"); ArrayList<Object> objects = new ArrayList<>(); objects.add("admin"); objects.add(18); objects.add("男"); request.setAttribute("list", objects); request.setAttribute("p", new person("admin")); return "thymeleaf"; } }
thymeleaf.html内容:(我新建的html)
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
[[(${name})]]
</body>
</html>
标签:port lang pid 之一 rop 引入 pojo ret person
原文地址:https://www.cnblogs.com/yangzhuxian/p/12787737.html