hibernate validater group validation

Definition of step one grouping
package com.test.validator.entity;

public interface GroupOne {

}
package com.test.validator.entity;

public interface GroupTwo {

}

Step 2: Set the grouping in the verification rule
@Size(min=1,max=14,groups= {GroupOne.class},message="{user.name.length.error}")
	@NotEmpty(groups= {GroupOne.class})
	private  String userName;
	private  String password;
	private  String password_safe;
	private  String address;
	private  String birthday;
	private  String homepage;
	
	@Email(groups= {GroupTwo.class})
	private  String email;
	private  String phone;

Step 3: The actual application of group verification in the example
@RequestMapping(value="add")
	public void add(HttpServletRequest request,HttpServletResponse response,@Validated(value=GroupTwo.class) User user, BindingResult bindingResult) {
		List<ObjectError> allErrors = bindingResult.getAllErrors();  
	   for(ObjectError e : allErrors){   
				System.out.println(e.getDefaultMessage());
	   }  
	}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325894325&siteId=291194637