springboot后台控制重定向

第一种方式:

1. 使用  @Controller  注解而不是  @RestController 

2.方法上不要加  @ResponseBody  然后直接返回你要去的页面  比如

return "views/home";

这样页面会跳转到你要去的 页面。但是地址栏的请求是不变的。

第二种方式:

1. 使用ajax请求,在成功的方法里执行新的请求

 $.ajax({
        url:   $.contextPath() + "/signOut",
        type: 'get',
        async: false,
        cache: false,
        contentType: 'application/json',
        dataType: 'json',
        success: function() {
            window.location.href="/login";
        },
        error: function() {
            commonAlert('出现了一点小问题','error');
        }
    });

此时将执行新的请求,重定向到你的Controller里

原文地址:https://www.cnblogs.com/UncleWang001/p/10620259.html