The main code in Userbean.java:
public class UserBean {@NotEmpty (field= "User ID", message= "{errors.required}")//using a label that cannot be empty @notempty, output error message private String userId, @NotEmpty (field= "user name", message= "{errors.required}") private String userName; @NotEmpty (field= "Login Password", Message= "{errors.required}") private String password;}
Code in Helloworldcontroller.ja:
Public String Initregister (model model, @Valid @ModelAttribute ("UserBean") UserBean userbean,bindingresult results) Throws SQLException {if (results.haserrors ()) {Log.info ("username or password cannot be empty! "); return" register ";}}
Code in Validationmessages.properties:
Errors.required={field} must be entered as a project and cannot be empty! The specific contents of the error message used to display the output!! field is Userbean.java in @notempty (field= "User ID", message= "{errors.required}") field value
The main statement that prints the error message to the HTML page:
<span th:if= "${#fields. HasErrors (' ${userbean.*} ')}" ><span th:errors= "${userbean.*}" ></span> </span><span th:text= "${message}" ></span>
Validation Implementing a check for information