spring mvc restful登录

spring mvc restful登录,spring,rest,redirect,model-view-controller,Spring,Rest,Redirect,Model View Controller,我是spring新手,因为我面临一些问题,当登录凭据成功时如何重定向到注册页面,否则返回用户不存在消息。我使用的是SpringREST,客户端是ajax @RequestMapping(value="/login",method=RequestMethod.POST, consumes=MediaType.APPLICATION_JSON_VALUE, produ

我是spring新手,因为我面临一些问题,当登录凭据成功时如何重定向到注册页面,否则返回用户不存在消息。我使用的是SpringREST,客户端是ajax

   @RequestMapping(value="/login",method=RequestMethod.POST,
                                consumes=MediaType.APPLICATION_JSON_VALUE,
                                produces=MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Login> login(@RequestBody Login login,UriComponentsBuilder ucBuilder)
{
            System.out.println("Checking Login Credentials...");

            boolean isValid=loginServiceBo.checkUserLogin(login);

            if(isValid)
            {
                System.out.println("Found...");
                return new ResponseEntity<Login>(login, HttpStatus.ACCEPTED);

            }
            System.out.println("Not Found...");
            return new ResponseEntity<>(login, HttpStatus.NOT_FOUND);   
}
@RequestMapping(value=“/login”,method=RequestMethod.POST,
consumes=MediaType.APPLICATION\u JSON\u值,
products=MediaType.APPLICATION\u JSON\u值)
公共响应身份登录(@RequestBody登录,UriComponentsBuilder ucBuilder)
{
System.out.println(“检查登录凭据…”);
布尔值isValid=loginServiceBo.checkUserLogin(login);
如果(有效)
{
System.out.println(“找到…”);
返回新的响应状态(登录,HttpStatus.ACCEPTED);
}
System.out.println(“未找到…”);
返回新的响应属性(登录,HttpStatus.NOT_FOUND);
}

由于您使用的是SpringREST服务,所以您需要向客户端发送状态代码,并根据这些状态代码可以在客户端重定向

if(isValid)
            {
                System.out.println("Found...");
                return new ResponseEntity<Login>(login, HttpStatus.OK);

            }
            System.out.println("Not Found...");
            return new ResponseEntity<>(login, HttpStatus.NOT_FOUND);  
$("button").click(function(){
    $.post("/login",{username: "xxxxx",password: "xxxxxx"},
    function(response){
        //redirect to registration page
    }, function(error) {
        //show user does not exist message
    });
});