【发布时间】:2018-08-30 02:15:04
【问题描述】:
我刚试过倾斜弹簧靴。 我用百里香,
list.html:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
>
<head>
<meta charset="UTF-8" />
<title>Thymeleaf in action</title>
</head>
<body>
<div th:replace="~{fragments/header}:: header"></div>
</body>
</html>
header.html:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
>
<head>
<meta charset="UTF-8" />
<title>Thymeleaf in action</title>
</head>
<body>
<div th:fragment="header">
header
</div>
</body>
</html>
控制器:
@RestController
@RequestMapping("/users")
public class UserController {
@Autowired
private UserRepository userRepository;
@GetMapping
public ModelAndView list(Model model) {
model.addAttribute("userList", userRepository.listUsers());
model.addAttribute("title", "account management");
return new ModelAndView("users/list", "userModel", model);
}
}
pom 文件:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>Blog</groupId>
<artifactId>Blog</artifactId>
<version>1.0-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
当我尝试打开 localhost:8080/users 页面时
白标错误页面 此应用程序没有 /error 的显式映射,因此您会看到这个 作为后备。
2018 年 3 月 20 日星期二 20:51:11 PDT 出现意外错误(类型=内部服务器错误,状态=500)。 解析模板“标题”时出错,模板可能不存在或可能不存在 任何已配置的模板解析器(用户/列表:11)都可以访问
不知道如何添加页眉和页脚
【问题讨论】:
-
请分享您的模板文件夹下的文件结构