spring - 错误:无法解析为表达式,th:action
问题描述
我想用 Thymeleaf 和 Spring 做一个 POST 请求。我的目标是从 HTML 接收选定的信息。但最初我只想在我从 th:action -“cidashboard/table”按下以下链接的提交按钮时重定向我。
我的控制器:
@GetMapping("cidashboard/filter/data")
public String allDataForFilter(Model model) {
model.addAttribute("projectsVariants", projectVariantService.findAllProjectsVariants());
model.addAttribute("builds", buildService.findAllBuildFromDB());
model.addAttribute("misraMessages", misraMessagesService.findAllMisraMessagesFromDb());
return "test2";
}
@PostMapping("cidashboard/table")
public String createTable() {
return "test1";
}
我的html页面:
<form th:action="@/cidashboard/table" method="post">
<select class="form-control">
<option th:each = "projectVariant : ${projectsVariants}" th:selected="${projectVariant.getProjectVariantId()}" th:text="${projectVariant.getProjectVariantName()}"></option>
</select>
<input type="submit" value="submit"/>
</form>
我收到了这个错误:
Could not parse as expression: "@/cidashboard/table"
解决方案
由于文档,您必须将relative
路径包装在brackets
.
<form th:action="@{/cidashboard/table}" method="post">
解析为
<form action="/cidashboard/table" method="post">
推荐阅读
- php - 在尝试更改 woocommerce 面包屑时尝试获取非对象错误的属性“名称”
- javascript - 注意:请求尚未完成
- python - 检查列表是否包含多个字符中的任何一个
- python - Python从字典列表中提取键的值
- java - 如何有效地删除字符串中的连续相同字符
- cryptography - 我无法修复的重复出现的 freqtrade bot 错误
- javascript - 获取 json 本地文件得到 404 未找到
- python - 暂停 python 直到显示绘图
- javascript - React native(来自 xcode)不在 iPhone 上运行但在模拟器上运行
- php - PHPMailer 用于联系表单并托管在 Heroku 上。发布请求给出 200 但邮件未发送