title: Spring @RequestMapping with optional parameters
body: <p>I have problem in my controller with optional params in requestmapping, look on my controller below:    </p>
  
  <pre><code>@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
  public ResponseEntity&lt;List&lt;Books&gt;&gt; getBooks() {
      return ResponseEntity.ok().body(booksService.getBooks());
  }
  
  @GetMapping(
      produces = MediaType.APPLICATION_JSON_VALUE,
      params = {"from", "to"}
  )
  public ResponseEntity&lt;List&lt;Books&gt;&gt;getBooksByFromToDate(
      @RequestParam(value = "from", required = false) String fromDate,
      @RequestParam(value = "to", required = false) String toDate) 
  {
      return ResponseEntity.ok().body(bookService.getBooksByFromToDate(fromDate, toDate));
  }
  </code></pre>
  
  <p>Now, when I send request like:</p>
  
  <pre><code>/getBooks?from=123&amp;to=123
  </code></pre>
  
  <p>it's ok, request goes to "getBooksByFromToDate" method
  but when I use send something like:</p>
  
  <pre><code>/getBooks?from=123
  </code></pre>
  
  <p>or</p>
  
  <pre><code>/getBooks?to=123
  </code></pre>
  
  <p>it goes to "getAlerts" method</p>
  
  <p>Is it possible to make optional params = {"from", "to"} in @RequestMapping ? Any hints?</p>