Springboot Study Verification Information International

Source: Internet
Author: User

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

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.