Example.
<!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>Post Course</title> </head> <body> <form method="post" th:object="${course}"> <h3>Enter course name: </h3> <input type="text" th:field="*{name}"/> <!--perform validation--> <span th:if="${#fields.hasErrors('name')}" th:errors="*{name}">Name Error</span> <h3>Enter lecture sections</h3> <textarea th:field="*{lecs}"></textarea> <h3>Enter tutorial sections</h3> <textarea th:field="*{tuts}"></textarea> <h3>Enter lab sections</h3> <textarea th:field="*{labs}"></textarea> <button>Submit your course</button> </form> </body> </html>Key points
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">Combine with the previous code, in model class add annotations:
@Data //@Data is lombok annotation which auto generates constructor, getters, and setters for the fields. public class MyClass { @Size(min=3, message="error message") // there are other constrains, such as @Pattern... private String someInfo; ... }@Slf4j: is in lombok which provides a logger. (Simply log.info("info");)