2016-11-22 106 views
0

因此,我正在嘗試替換我的Spring 3.0控制器方法中的HttpServletRequestHttpServletResponse變量。我最近我知道,我可以替換以下老辦法:用Spring註釋替換HttpServletRequest和HttpServletResponse

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> 

我相信有更多的,我真的想實現儘可能多的這些快捷方式儘可能的。任何人都可以給我一個完整列表的資源?

回答

0

Spring Reference是你的朋友!只要捲動過table of content的部分 「22.3.3定義@RequestMapping處理方法。」

所以一些註解你錯過:

  • @RequestBody
  • @SessionAttribute
  • @MatrixVariable

但也有一些不需要註釋的快捷方式,而只是通過類型(hav Ë看看Supported method argument types):

  • Locale
  • HttpSession
  • HttpEntity
  • ...
+0

啊,我忘了提RequestBody我已經用它,一個人的偉大! 。 SessionAttribute看起來很有前景,但MatrixVariable只是給出了一個名稱值映射的權利?這就是我想要避免的事情 – chrisgotter

相關問題