为什么我的“addcar”视图中的表单不会显示消息?
My Controller method
@RequestMapping(value = "/add-car", method = RequestMethod.POST)
public String addCar(@ModelAttribute("carDto") @Valid CarDto carDto,
BindingResult bindingResult, ModelMap modelMap) {
if (bindingResult.hasErrors()) {
if (carDto.isDealerCar() == false) {
String status = "userCession";
boolean dealerCar = false;
boolean accepted = false;
int numberOfTestDrives = 0;
modelMap.addAttribute("carDto", new CarDto());
modelMap.addAttribute("status", status);
modelMap.addAttribute("dealerCar", dealerCar);
modelMap.addAttribute("accepted", accepted);
modelMap.addAttribute("numberOfTestDrives", numberOfTestDrives);
return "car/addcar";
}
我的表单示例(addcar视图)
<div class="form-group">
<h3>
<span class="label label-default">Numer VIN</span>
</h3>
<input type="text" class="form-control" th:field="*{vin}" />
<div class="alert alert-warning"
th:if="${#fields.hasErrors('vin')}">
<span th:errors="*{vin}">Error</span>
</div>
</div>
当我回到我的addcar视图但它没有我的设置值时,它工作,我无法提交表单。 如上所述,新表单通过但没有错误消息。
答案 0 :(得分:-1)
你可以尝试:
public String addCar(@requestParam(Map)){