用春季注释代替httpservletrequest和httpservletresponse



因此,我当前正在尝试在我的Spring 3.0控制器方法中替换HttpServletRequestHttpServletResponse变量。我最近知道我可以用以下方式替换以下旧方法:

 HttpServletRequest.getParameter       -> @RequestParameter
 HttpServletRequest.getCookies         -> @CookieValue //with actual name no array indexing!
 HttpServletRequest.getPathInfo        -> @PathValue   //with actual name no array indexing!
 HttpServletRequest.getHeader          -> @RequestHeader
 HttpServletResponse.getWriter().write -> <just return a String>

我确定还有更多,我真的很想实现尽可能多的此类快捷方式。谁能为我指出一个带有完整列表的资源?

春季参考是您的朋友!只需在" 22.3.3。定义@requestmapping处理程序方法"部分的内容表上滚动

所以您错过了一些注释:

  • @RequestBody
  • @SessionAttribute
  • @MatrixVariable

但是也有一些不需要注释的快捷方式,而是仅由那里的类型映射(请查看支持的方法参数类型):

  • Locale
  • HttpSession
  • HttpEntity
  • ...

最新更新