To log in as an example:
1.controller sign-in method:
@RequestMapping ("/ssoauth/login")
@ResponseBody
Public responsevalue login (@Valid @RequestBody loginparam param, bindingresult result) {
//Validate data legitimacy
if (result.haserrors ()) {
Responsevalue responsevalue = Response Value.newinstance (headcode.bad_request);
Responsevalue.gethead (). Setmsg (Result.getfielderror (). Getdefaultmessage ());
return responsevalue;
}
String loginName = Param.getloginname ();
String pwd = Param.getpassword ();
if (loginvalidation.exist (loginName) = = False) {
Responsevalue value = responsevalue.newinstance (headcode.not _find);
Value.gethead (). SETMSG ("User information does not exist! ");
return value;
}
if (Loginvalidation.verify (loginName, pwd) = = False) {
Responsevalue value = responsevalue.newinstance (headcode.bad_request);
Value.gethead (). setmsg ("The password is incorrect! ");
return value;
}
Return result (LoginName, New Date ());
}
The key to this approach is that @valid annotations and Bindingresult are used together to verify that the incoming information is legitimate, Loginparam this is the validation object.
2. Verify the object:
public class Loginparam implements Serializable {
Private static final long serialversionuid = 1L;
@NotBlank (message= "{notblank.name}")
@Length (min=0, max=50, message= "LoginName length out of range")
Private String LoginName;
@NotBlank (message= "{Notblank.password}")
@Length (min=6, max=10, message= "password length out of range")
private String password;
Public String Getloginname () {
return loginName;
}
public void Setloginname (String loginName) {
This.loginname = LoginName;
}
Public String GetPassword () {
return password;
}
public void SetPassword (String password) {
This.password = password;
}
}
Springboot Study Verification Information International