title: Spring Boot Date conversion from Form
body: <p>I'm having a few issues with getting a date from a controller because I don't understand what's the right format for it to work.</p>
  
  <p><strong>Controller:</strong></p>
  
  <pre><code>@RequestMapping(value = "/findFlights", method = RequestMethod.POST)
      public String findFlights(@RequestParam("from") String from, @RequestParam("to") String to,
              @RequestParam("departureDate") @DateTimeFormat(pattern = "YYYY-MM-DD") LocalDate departureDate, Model model) {}
  </code></pre>
  
  <p><strong>Form:</strong></p>
  
  <pre><code>&lt;form th:action="@{/findFlights}" method="POST"&gt;
          From:&lt;input type="text" name="from" required/&gt;
          To:&lt;input type="text" name="to" required/&gt;
          Departure Date:&lt;input type="date" name="departureDate"  required /&gt;
          &lt;input type="submit" value="Search"/&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>When I submit the form it always gives me an error no matter what the format of the date is :( Here is the error:</p>
  
  <blockquote>
    <p>Failed to convert value of type 'java.lang.String' to required type
    'java.time.LocalDate'; nested exception is
    org.springframework.core.convert.ConversionFailedException: Failed to
    convert from type [java.lang.String] to type
    [@org.springframework.web.bind.annotation.RequestParam
    @org.springframework.format.annotation.DateTimeFormat
    java.time.LocalDate] for value '2018-11-05'; nested exception is
    java.lang.IllegalArgumentException: Parse attempt failed for value
    [2018-11-05]</p>
  </blockquote>
  
  <p>If I specify the <code>@DateTimeFormat</code> annotation I thought that the conversion would be done automatically.</p>