title: Spring MVC Annotated Controller
body: <p>I have a controller which has a few actions, which are triggered by hitting various buttons on the page.  I would like to have a default action, but am unsure how to annotate the method.  Here is an example:</p>
  
  <pre><code>@Controller
  @RequestMapping("/view.jsp")
  public class ExampleController {
  
      @RequestMapping(method = RequestMethod.GET)
      public ModelAndView displayResults() {
          ModelAndView mav = new ModelAndView("view");
          mav.addObject("queryResults", methodToQueryDBForListing());
          return mav;
      }
  
      @RequestMapping(method = RequestMethod.POST, params="submit=Action 1")
      public ModelAndView action1(@RequestParam("selectedItemKey") String key) {
          ModelAndView mav = new ModelAndView("action1");
          //Business logic
          return mav;
      }
  
      @RequestMapping(method = RequestMethod.POST, params="submit=Action 2")
      public ModelAndView action2(@RequestParam("selectedItemKey") String key) {
          ModelAndView mav = new ModelAndView("action2");
          //Business logic
          return mav;
      }
  
      //A few more methods which basically do what action1 and action2 do
  }
  </code></pre>
  
  <p>How can I annotate a method which will act on a POST with any submit button pressed with no key selected?</p>
  
  <p>I have tried:</p>
  
  <pre><code>@RequestMethod(method = RequestMethod.POST, params="!selectedItemKey")
  @RequestMethod(method = RequestMethod.POST)
  </code></pre>
  
  <p>I'd really hate it if I had to set required = false on each of the methods which take RequestParams and then conditionally check to see if one comes in or not...  Is there a way to annotate this to work properly?</p>