- 通过redirect返回String类型跳转
@Controller
@RequestMapping("/modules/Login")
public class AuthLoginController {
@RequestMapping("/login")
public String login() {
return "redirect:" + url;
}
}
需要注意的是controller层不能使用@RestController注解,因为这个注解是把所有的返回都设置成了json格式,不能返回一个视图,使用@Controller就可以
2. HttpServletResponse跳转
@RequestMapping("/modules/Login1")
public class AuthLoginController {
@RequestMapping("/login1")
public void login(HttpServletRequest request, HttpServletResponse response) {
response.sendRedirect(url)
}
}
- ModelAndView跳转
@RequestMapping("/modules/Login2")
public class AuthLoginController {
@RequestMapping("/login2")
public ModelAndView login(HttpServletRequest request, HttpServletResponse response) {
return new ModelAndView(url)
}
}