springboot 重定向(HttpServletResponse实现)


springboot 重定向

***********************************

示例

@RestController
public class Hello3Controller {

    @RequestMapping("/hello")
    public void hello(HttpServletRequest request, HttpServletResponse response){
        request.setAttribute("name","瓜田李下");

        ModelAndView mv=new ModelAndView();
        mv.addObject("name2","海贼王");

        try{
            response.sendRedirect("/redirect");
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @RequestMapping("/redirect")
    public String redirect(String name2, HttpServletRequest request, ModelAndView mv){
        System.out.println(request.getAttribute("name"));
        System.out.println(name2);
        System.out.println(mv.getModelMap().getAttribute("name2"));

        return "redirect";
    }
}

*********************

控制台输出

null
null
null

说明:使用response跳转不能通过request、ModelAndView传递数据

发布了320 篇原创文章 · 获赞 91 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_43931625/article/details/103615516