繁体   English   中英

Spring 引导和 Thymeleaf:通过导航栏链接切换页面

[英]Spring Boot and Thymeleaf: Switching Pages through Nav bar links

我正在利用以下方式开展汽车经销商项目:

Java 8

Spring开机

Thymeleaf

AWS mySQL 数据库

我目前的问题是我无法使用导航栏在 html 页面之间移动。 i have 5 html pages( index.html, customer.html, employee.html, vehicle.html, and transaction.html)

来自 index.html 的代码:

    <a class="active" th:href="@{/index.html}"><i class="(Put css class here)"></i> Home</a>
    <a th:href="@{/vehicle.html}"><i class="(Put css class here)"></i> Vehicles </a>
    <a th:href="@{/customer.html}"><i class="(Put css class here)"></i> Customers </a>
    <a th:href="@{/employee.html}"><i class="(Put css class here)"></i> Employees </a>
    <a th:href="@{/transaction.html}"><i class="(Put css class here)"></i> Transactions </a>

来自 IndexController 的代码:

@Controller
public class IndexController {

@RequestMapping("/index")
public String index(){
    return "index";
}

}

该页面在首次打开时在 localhost:8088 正常加载,但是当我单击“主页”或任何其他按钮时,我得到一个 404。

如果有人能简单地指出我的大致方向,我将不胜感激。

相反,请尝试在 controller 中为这些不同的链接发出 GetMapping 请求。

例子:

    @GetMapping("/customer")
  public String getCustomer(){
    return "customer.html";
 }

在您的 html class (导航栏)中:

    <a th:href="@{/customer}"><i class="(Put css class here)"></i> Customers </a>

*确保删除.html,但这取决于您在配置中的配置方式,但我相信这是默认配置。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM