Не отрабатывает валидация spring
Пишу CRUD приложение на Спринге, и захотел сделать при создании блога валидацию данных, добавил нужные аннотации в модель, прописал все что нужно в контроллере, добавил в HTML нужные поля с Thymeleaf, а оно просто не работает, вообще ничего не поменялось
Вот какие аннотации прописал в модель
@Min(value = 0, message = "id != < 0")
private int id;
@Size(min = 10, max = 10000)
private String text;
@NotEmpty(message = "Please input author name")
@Size(min = 10)
private String author;
private String publicationTime;
@NotEmpty(message = "Please input title for publication")
@Size(min = 10)
private String title;
Реализация добавления нового блога в веб приложение в контроллере
@PostMapping()
public String create(@ModelAttribute("blogs") @Valid BlogModel blogModel,
BindingResult bindingResult) {
if(bindingResult.hasErrors()){
return "BlogDAO/blogadd";
}
blogDAO.save(blogModel);
return "redirect:/blog";
}
Зависимость Hybernate validator в pom.xml занесена
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>7.0.4.Final</version>
</dependency>
Вот в чем проблема, я хочу что бы при добавлении новой публикации блога у меня размер текста был не меньше 10 символов, а поля автор и title не были пустыми, вот я прописал вроде все в html файле
<form th:method="POST" th:action="@{/blog}" th:object="${blogs}">
<label for="author">Enter author name: </label>
<input type="text" th:field="*{author}" id="author"/>
<div style="color:red" th:if="${#fields.hasErrors('author')}" th:errors="*{author}">Name Error</div>
<br/>
<label for="title">Enter title name: </label>
<input type="text" th:field="*{title}" id="title"/>
<div style="color:red" th:if="${#fields.hasErrors('title')}" th:errors="*{title}">Title Error</div>
<br/>
<label for="text">Enter ur text: </label>
<input type="text" th:field="*{text}" id="text"/>
<div style="color:red" th:if="${#fields.hasErrors('text')}" th:errors="*{text}">Text Error</div>
<br/>
<input type="submit" value="Create!"/>
Но если я попытаюсь создать пользователя с пустыми полями, мне ничего не помешает
В чем может быть проблема?


