两者有什么区别?两者都有getParameter
方法和setAttribute
方法,那么两者的区别在哪里呢?
1) 一般情况下哪个更好用?
2)请说明具体的使用场景。
最佳答案
javadoc of WebRequest对这个主题很清楚:
Generic interface for a web request. Mainly intended for generic web request interceptors, giving them access to general request metadata, not for actual handling of the request.
(强调我的)。
javadoc 链接到 WebRequestInterceptor,它说:
Interface for general web request interception. Allows for being applied to Servlet request as well as Portlet request environments, by building on the WebRequest abstraction.
所以,基本上,除了在 WebRequestInterceptor 中,您不应该使用 WebRequest。他们引入这个接口(interface)是为了能够编写适用于 servlet 和 portlet 的拦截器。除此之外,如果您确实需要访问 Spring MVC Controller 中的请求,您应该使用标准的 HttpServletRequest。
关于java - Spring MVC 中的 WebRequest 和 HttpServletRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24342533/