Validation Implementing a check for information

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.