The betweern difference returns a plain modelandview and returns a redirection and redirection model

I just found out Spring MVC web stream. I am confused by this:

return new ModelAndView("test");
return new ModelAndView("redirect:test");

Is call forwarding the same as response.sendRedirect()? And I'm just checking the Spring link, in fact, return new RedirectView()doing the same thing as response.sendRedirect(). So what's the difference between the three?

+4
source share
1 answer

ModelAndView ( "test" ) ModelAndView ( ": " ) . RequestDispatcher request.sendRedirect() requestdispatcher sendredirect,

": " HttpServletResponse.sendRedirect(), RedirectView .
IMO, API , , , - -.

RedirectView HttpServletResponse.sendRedirect(), HTTP. URI URL- . , / , .
http://docs.spring.io/spring/docs/3.1.x/spring-framework-reference/html/mvc.html

, spring MVC, . . ,

public String doSomething(Model model){
    return "test";
}
public ModelAndView i_am_similar_to_doSomething(){
    return new ModelAndView("test");
}

//You can guess that you can do the same thing with redirect.

- , , .

+1

Source: https://habr.com/ru/post/1537845/


All Articles