title: Spring Boot : How to bind list of objects on POST in thymleaf
body: <p>I have a list of records on <code>GET</code> request which is shown on UI with a checkbox.
  </p>
  
  <pre><code>@GetMapping("/list")
  public String list(Model model) {
      model.addAttribute("records", createRecords());
      return "list";
  }
  </code></pre>
  
  
  
  <p>This is my <code>Record</code> <code>POJO</code>:</p>
  
  <pre class="lang-java prettyprint-override"><code>class Record {
      private boolean selected;   
      private Integer id; 
      private String name;    
      private String phone;
      //....
  </code></pre>
  
  <p>
  I am showing in UI as below:</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;th:block th:each = "record : ${records}"&gt;
  &lt;tr&gt;
      &lt;td&gt;&lt;input type="checkbox" th:field="*{selected}" th:checked="${record.selected}" /&gt;&lt;/td&gt;
      &lt;td th:field="*{id}" th:text="${record.id}" /&gt;
      &lt;td th:field="${name}" th:text="${record.name}" /&gt;
      &lt;td th:field="${phone}" th:text="${record.phone}" /&gt;
  &lt;/tr&gt;
  &lt;/th:block&gt;
  </code></pre>
  
  
  
  <p>I am having hard time to get the <code>List</code> of selected records on <code>POST</code> from <code>UI</code>. I just gets one object back from <code>POST</code>.</p>
  
  <p>I want something like this in <code>POST</code> mapping:</p>
  
  <pre class="lang-java prettyprint-override"><code>@PostMapping("/list")
  public String select(@ModelAttribute ArrayList&lt;Record&gt; records) {
      //... at least ids of selected records
      //... or all the records back with selected
  </code></pre>
  
  <p>Please help.</p>