我有这个控制器:
@Controller
@Slf4j
@RequestMapping("/natalchart")
public class NatalChartDataController {
@GetMapping({"/data"})
public String data(Model model, NatalChartDataPayload data) {
model.addAttribute("months", Month.values());
return "natalChartData";
}
@ModelAttribute("data")
public NatalChartDataPayload natalChartDataPayload(){
return NatalChartDataPayload.builder().build();
}
@PostMapping("/create")
public String createNatalChart(@Valid @ModelAttribute NatalChartDataPayload data,
BindingResult result) {
if (result.hasErrors()) {
return "natalChartData";
}
..
}
这是模板:
<div class="container" data-aos="fade-up">
<form method="post" th:action="@{/natalchart/create}" th:object="${data}">
<div class="row">
<div class="col-lg-8">
<h4>Enter your birth details to create your natal chart</h4>
<p> </p>
<p> </p>
<div th:if="${#fields.hasErrors('email')}" th:errors="*{email}">Email Error</div>
和错误:
但我在模板中没有看到错误消息
该错误看起来像模型属性仍然命名为默认的“natalChartDataPayload”而不是预期的“数据”。