response 重定向

背景:

controller层需要重定向到其他html界面时,需要用如下代码

// 设置302状态码
response.setStatus(302);
// 设置location响应头
response.setHeader("location", "../adv.html");
// 注意:一次重定向,向服务器发送两次请求

注意:

@Controller:可以跳转到界面

@RestController:不可以跳转到html页面,返回字符串

猜你喜欢

转载自www.cnblogs.com/wangxue1314/p/12714887.html