SPRINGMVC form label <%@ taglib prefix= "form" uri= "Http://www.springframework.org/tags/form"%>
On the page
<form:input path= "AccountName"/>
<form:errors path= "AccountName" cssstyle= "color:red"/>
How does the data passed by the page bind to the project entity?
1, adding commandname= "user" to the form label in the JSP means that you want to bind the contents of this tag to
You can also use modelattribute= "student" to label the converted object in JSP
2. Identify the entities that need to be bound
Account name
@NotEmpty (message= "Accountnamenotempty") tips to be displayed on the page
Private String AccountName;
Password
@NotEmpty (message= "Passwordnotempty")
private String password;
3, in the controller
@RequestMapping (value = "/show", method = Requestmethod.post)
Public String Show (@Valid @ModelAttribute ("user") user user, Errors validerrors, Modelmap modelmap) {
System.out.println ("AccountName" + user.getaccountname ());
System.out.println (Validerrors.haserrors ());
Validation of validation data
if (Validerrors.haserrors ()) {
return "Login";
}
@Valid @ModelAttribute ("user") user user, Errors validerrors,
@Valid for entities that require validation
@ModelAttribute ("user") explicitly specifies which entity to validate, followed by the entity
Errors Validerrors, immediately behind @Valid
5, also need to be in the controller
Bind Login
@ModelAttribute ("User")
Public User GetUser () {
return new User ();
}
The method that is @ModelAttribute annotated is executed before each method of the controller is executed, so use it sparingly for the use of a controller to map multiple URLs
Represents injecting an entity class
SPRINGMVC form Annotations Simple validation