我想对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"
答案 0 :(得分:1)
由于documentation,您必须将OrderId
路径包装在relative
中。
brackets
已解析为
<form th:action="@{/cidashboard/table}" method="post">