Spring Security Thymeleaf Validation
We will develop a simple User Registration Module using Spring Boot 2, Spring MVC, Spring Security, Hibernate 5, Thymeleaf and MySQL. We validate the user registration fields with hibernate validator annotations and a custom field matching validator to validate if the email and/or password fields match. We will create Role-based Spring security with a MySQL database.We will develop two main functionalities:1. Register user (stored data into MySQL database).2. Login Authentication - validate user login credentials with database email and password.
Spring Thymeleaf Example
We configure Hibernate using the application.properties file located in the src/main/resources/ folder. Note that we also configure thymeleaf view resolver. This controller is mapped to “/registration” URI. We use the UserRegistrationDto to process and validate the user registration form and inject it using the @ModelAttribute('user') annotation. When the form is submitted it’s automatically validated and errors are available in the BindingResult. Next, we check if a user doesn’t already exist with the submitted email.
Aug 31, 2015 I have been trying to get different functionalities to work with Thymeleaf for two days now and been very unsuccessful. I have only been able to get it to work with spring-boot, however right now I am using spring-MVC.
If the form has any errors, we return to the registration page. Otherwise, we redirect and inform the user the registration procedure is complete.
Pom.xml 4.0.0com.onlinetutorialspoint.springbootvalidationspringbootvalidation0.0.1-SNAPSHOTorg.springframework.bootspring-boot-starter-parent1.5.9.RELEASE1.8org.springframework.bootspring-boot-maven-pluginorg.springframework.bootspring-boot-starter-thymeleaforg.hibernatehibernate-validatororg.apache.tomcat.embedtomcat-embed-elorg.springframework.bootspring-boot-starter-testtestspring-releasesSpring ReleasesReleasesLogin Controller.