java Spring MVC 请求和响应流程说明

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27918643/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 12:37:21  来源:igfitidea点击:

Spring MVC request and response flow explanation

javaspringhibernatespring-mvcannotations

提问by Balasubramani

I can't find correct client request flow in below syntax.Could someone please clarify what is happening here?

我在下面的语法中找不到正确的客户端请求流。有人可以澄清这里发生了什么吗?

Client(1) --> Dispatcher Servlet(2) --> Handler Mapping(3) --> Controller(4) -->
ModelAndView(5) --> viewResolver(6) --> View(7) --> Client(1) 

If possible please specify what are the corresponding spring classes/interfaces used in spring MVC process.

如果可能,请指定在 spring MVC 过程中使用的相应 spring 类/接口是什么。

回答by Harshal Patil

  1. Request will be received by DispatcherServlet.
  2. DispatcherServletwill take the help of HandlerMappingand get to know the @Controllerclass name associated with the given request.
  3. So request transfer to the @Controller, and then @Controllerwill process the request by executing appropriate methods and returns ModelAndViewobject (contains Model data and View name) back to the DispatcherServlet
  4. Now DispatcherServletsend the model object to the ViewResolverto get the actual view page.
  5. Finally, DispatcherServletwill pass the Model object to the View page to display the result.
  1. 请求将由 接收DispatcherServlet
  2. DispatcherServlet将借助HandlerMapping并了解@Controller与给定请求关联的类名。
  3. 所以请求转移到@Controller,然后@Controller将通过执行适当的方法处理请求并将ModelAndView对象(包含模型数据和视图名称)返回给 DispatcherServlet
  4. 现在DispatcherServlet将模型对象发送到ViewResolver以获取实际视图页面。
  5. 最后,DispatcherServlet将Model对象传递给View页面来显示结果。

回答by Singupurapu prudhvi raj

Spring Flow First Request from JSP/HTML will hit the dispacher servlet, Based on the xml file it will go to particular controller, After going to controller it search for request mapping , based on request mapping it will go to the particular method and follows instructions and takes the model and view and give it to view resolver via dispacher servlet and view resolver will display the view.

来自 JSP/HTML 的 Spring Flow First Request 将命中 Dispacher servlet,根据 xml 文件,它将转到特定的控制器,在去控制器后搜索请求映射,根据请求映射,它将转到特定的方法并按照说明执行并获取模型和视图,并通过调度程序 servlet 将其提供给视图解析器,视图解析器将显示该视图。