我不知道发生了什么,但是百里香验证错误不起作用。我没有更改代码。我有一个jakson绑定异常,我解决了。之后,错误消息没有显示,但是bindingresult在控制器中显示了错误。
下面是代码。请帮忙。我必须尽快提交这个项目。
<div class="form-group">
<label for="exampleTextarea1">Description</label>
<textarea class="form-control" id="exampleTextarea1"
th:field="*{description}" rows="2"></textarea>
<div th:if="${#fields.hasErrors('description')}"
th:style="'color:red'">
<p>Enter description</p>
</div>
</div>
表格标签
<form class="forms-sample"
th:action="@{~/AdminController/saveImage}"
th:object="${uploadData}" method="post">
控制器
@Autowired
Environment var;
@Autowired
CategoriesServices categoriesServices;
@Autowired
SubCategoriesServices subcategoriServices;
@PostMapping("saveImage")
String saveImage( @Valid @ModelAttribute("uploadData") UploadData uploadData ,BindingResult result,Model model) throws Exception {
if(result.hasErrors()) {
log.warning("errors");
goToImage(model);
return "uploadImages";
}
goToImage(model);
return "uploadImages";
}
private void goToImage(Model model) throws Exception {
UploadData data=new UploadData();
data.setCategory(categoriesServices.getCategories().getCategorieslist());
model.addAttribute("uploadData",data);
}