`
k1280000
  • 浏览: 195887 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

springmvc

阅读更多

DispatcherServlet 

  1. RequestContextUtils  can get WebApplicationContext
  2. HandlerMapping HandlerMapping是把一个URL指定到一个Controller 
  3. HandlerAdapter HandlerAdapter是促进DispatcherServlet和第三方框架简单集成的系统级接口。除非使用第三方框架,否则该接口及其实现一般就会对开发者隐藏。DispatcherServlet还会串连在ApplicationContext中的多个适配器,并同时根据Ordered接口对它们进行排序。
  4. HandlerExceptionResolver 
  5. ViewResolver 

DispatcherServlet  workflow:

http://www.processon.com/view/link/55557188e4b090bd2cad57cd

 

 

Session access may not be thread-safe, in particular in a Servlet environment. Consider setting theRequestMappingHandlerAdapter's "synchronizeOnSession" flag to "true" if multiple requests are allowed to access a session concurrently.

 

 

Supported method return types

The following are the supported return types:

 

  • ModelAndView object, with the model implicitly enriched with command objects and the results of @ModelAttribute annotated reference data accessor methods.
  • Model object, with the view name implicitly determined through a RequestToViewNameTranslator and the model implicitly enriched with command objects and the results of @ModelAttribute annotated reference data accessor methods.
  • Map object for exposing a model, with the view name implicitly determined through a RequestToViewNameTranslator and the model implicitly enriched with command objects and the results of @ModelAttribute annotated reference data accessor methods.
  • View object, with the model implicitly determined through command objects and @ModelAttribute annotated reference data accessor methods. The handler method may also programmatically enrich the model by declaring a Model argument (see above).
  • String value that is interpreted as the logical view name, with the model implicitly determined through command objects and@ModelAttribute annotated reference data accessor methods. The handler method may also programmatically enrich the model by declaring a Model argument (see above).
  • void if the method handles the response itself (by writing the response content directly, declaring an argument of typeServletResponse / HttpServletResponse for that purpose) or if the view name is supposed to be implicitly determined through aRequestToViewNameTranslator (not declaring a response argument in the handler method signature).
  • If the method is annotated with @ResponseBody, the return type is written to the response HTTP body. The return value will be converted to the declared method argument type using HttpMessageConverters. See the section called “Mapping the response body with the @ResponseBody annotation”.
  • An HttpEntity<?> or ResponseEntity<?> object to provide access to the Servlet response HTTP headers and contents. The entity body will be converted to the response stream using HttpMessageConverters. See the section called “Using HttpEntity”.
  • An HttpHeaders object to return a response with no body.
  • Callable<?> can be returned when the application wants to produce the return value asynchronously in a thread managed by Spring MVC.
  • DeferredResult<?> can be returned when the application wants to produce the return value from a thread of its own choosing.
  • ListenableFuture<?> can be returned when the application wants to produce the return value from a thread of its own choosing.
  • Any other return type is considered to be a single model attribute to be exposed to the view, using the attribute name specified through@ModelAttribute at the method level (or the default attribute name based on the return type class name). The model is implicitly enriched with command objects and the results of @ModelAttribute annotated reference data accessor methods.

 

@ModelAttribute

The @ModelAttribute annotation can be used on methods or on method arguments

An @ModelAttribute on a method indicates the purpose of that method is to add one or more model attributes. Such methods support the same argument types as@RequestMapping methods but cannot be mapped directly to requests. Instead @ModelAttribute methods in a controller are invoked before @RequestMappingmethods, within the same controller.

 

In the first, the method adds an attribute implicitly by returning it. In the second, the method accepts a Model and adds any number of model attributes to it. You can choose between the two styles depending on your needs.

 

 

Support for the Last-Modified Response Header To Facilitate Content Caching

There are two key elements to note: calling request.checkNotModified(lastModified) and returning null. The former sets the response status to 304 before it returns true. The latter, in combination with the former, causes Spring MVC to do no further processing of the request.

 

 

 

 

 

 

 

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics