如何在 Spring Boot Thymeleaf 模板引擎中链接另一个 html 页面?

Sai*_*pta 4 spring spring-mvc thymeleaf spring-boot

我有以下 Spring Boot 项目结构(使用 Thymeleaf)-

在此处输入图片说明

现在,当我试图引用defect-details.htmlindex.html它不能被发现。我尝试了以下所有选项均无济于事:

1.<a th:href="@{/defect-details.html}">

2.<a th:href="@{defect-details.html}">

3.<a href="defect-details.html">

每次都说There was an unexpected error (type=Not Found, status=404)

请帮助查找问题。

Sai*_*pta 5

(正如JBNizet在评论中指出的那样)根据 MVC 设计架构,最好使用控制器来呈现视图而不是视图到视图的链接。我所要做的就是更新我的 Controller 类:

@RequestMapping("/defect-details")
public String defectDetails() {
    return "defect-details";
}
Run Code Online (Sandbox Code Playgroud)

在 Thymeleaf 模板中:

<a th:href="@{defect-details}">
Run Code Online (Sandbox Code Playgroud)