java - Spring Boot 和 Thymeleaf:通过导航栏链接切换页面
问题描述
我正在利用以下方式开展汽车经销商项目:
爪哇 8
弹簧靴
百里香叶
AWS mySQL 数据库
我目前的问题是我无法使用导航栏在 html 页面之间移动。我有 5 个 html 页面(index.html、customer.html、employee.html、vehicle.html 和 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。
如果有人能简单地指出我的大致方向,我将不胜感激。
解决方案
相反,尝试在控制器中为这些不同的链接发出 GetMapping 请求。
例子:
@GetMapping("/customer")
public String getCustomer(){
return "customer.html";
}
在您的 html 类(导航栏)中:
<a th:href="@{/customer}"><i class="(Put css class here)"></i> Customers </a>
*确保删除 .html,但这取决于您在配置中的配置方式,但我相信这是默认配置。
推荐阅读
- swiftui - 如何对@ViewBuilder 函数进行单元测试?
- amazon-web-services - Kinesis 客户端库,预先创建的 DynamoDB 表
- javascript - discord.js (node:9852) UnhandledPromiseRejectionWarning: ReferenceError: msg is not defined
- c# - 为什么我为检索 DataGridView 的二级属性而执行的自定义 TypeDescriptor 不起作用?
- postgresql - Postgres 在所有字段的开头和结尾添加一个空格
- azureservicebus - Azure 服务总线上的“辅助连接字符串”的用途是什么?
- notifications - OneM2M:通知 IN-CSE 在 MN-CSE 上创建的新资源
- json - 可选+可空值的Gson反序列化
- c++ - Armadillo C++ 配置检查
- python - fast_executemany=True 等效于 SQLALCHEMY 中的 Oracle