Get HttpServletRequest and httpservletresponse from spring MVC
The singleton pattern most commonly used by beans in spring
What about HttpServletRequest and httpservletresponse in spring MVC controller?
1. Pass in httpservlet like parameters in the interface function
The real request is obtained in this way, and the response object has nothing to say
2. @ Autowired injection definition class attribute
In this way, the request and response proxy objects are obtained. What are the benefits of doing so?
The controller bean mentioned above is in singleton mode, so all requests actually access the same controller object,
We can infer that the request and response here are also the same what? Isn't this a mess? Isn't it agreed that every request will have a request and response object?
In fact, any way we access request and response is to find the real request and response through the agent first
Object, and then execute the corresponding method
The final request and response are stored in ThreadLocal
The implementation method stored in ThreadLocal is no problem for the request - > single thread processing model,
If you want to open another sub thread, you have to pass these two objects through parameters, so I personally think the first implementation method is better