else if(e instanceof UserNotFoundEx) { result.setState(5001); result.setMessage("用户数据不存在"); } else if(e instanceof PasswordNotMatchEx) { result.setState(5002); result.setMessage("用户密码错误"); }
@RequestMapping("login")
public JsonResult<User> login(String username,String password)
{
iUserService.login(username, password);
return new JsonResult<>(OK);
}
<script type="text/javascript">
$("#btn-login").click(function () {
$.ajax({
url:"/users/login",
data:$("#form-login").serialize(),
type:"POST",
dataType:"json",
success:function (json) {
if(json.state == 200)
{
alert("登录成功");
location.href = "index.html";
}
else{
alert("登录失败");
}
},
error:function (xhr) {
alert("登录产生未知异常" + xhr.message);
}
});
});
</script>