当前位置: 代码迷 >> 综合 >> @RestController使用 redirect 重定向
  详细解决方案

@RestController使用 redirect 重定向

热度:27   发布时间:2023-12-27 06:58:31.0

springmvc的Controller中重定向一般使用return "redirect:/url";即可。

而Spring Boot中当我们使用了@RestController注解,上述写法只能返回字符串,解决方法如下:

将一个HttpServletResponse参数添加到方法然后调用 response.sendRedirect("some-url");

	@RequestMapping(value = "/userLogin", method = RequestMethod.GET)@ApiOperation(value = "获取登录url")public void userLogin(HttpServletResponse response) throws IOException {response.sendRedirect(baseUrl);}


 

  相关解决方案