title: Combine GET and POST request methods in Spring
body: <p>I have a resource that supports both <code>GET</code> and <code>POST</code> requests. Here a sample code for a sample resource:</p>
  
  <pre><code>@RequestMapping(value = "/books", method = RequestMethod.GET)
  public ModelAndView listBooks(@ModelAttribute("booksFilter") BooksFilter filter, two @RequestParam parameters, HttpServletRequest request)
      throws ParseException {
          LONG CODE
  }
  
  
  @RequestMapping(value = "/books", method = RequestMethod.POST)
  public ModelAndView listBooksPOST(@ModelAttribute("booksFilter") BooksFilter filter, BindingResult result)
          throws ParseException {
          SAME LONG CODE with a minor difference
  }
  </code></pre>
  
  <p>The code in the two methods is practically the same, except for lets say a variable definition. The two methods can be easily combined using <code>method = {RequestMethod.POST, RequestMethod.GET}</code>, and a simple <code>if</code> inside. I tried, but it doesn't work, because the two methods have a different parameter at the end, i.e. <code>HttpServletRequest</code> and <code>BindingResult</code> (the <code>@RequestParam</code>'s are not required and therefore not needed in the <code>POST</code> request). Any ideas how to combine the two methods?</p>