title: Set default value of select in thymeleaf
body: <p>I'm using Spring boot + thymeleaf and I'm trying to set the default value of a select element in order to show the selected object that is stored in database (edit form).</p>
  
  <p>To do that, from the controller, I insert into the model the entity with its values, but, when I try to set the default value of the select, it always gets the first option.</p>
  
  <p>This is the code:</p>
  
  <pre><code>    &lt;select class="selectpicker"
          id="alarmPeriod" name="alarmPeriod"                                                     
          th:selected="${alarm.alarmPeriod}" 
          th:value="${alarm.alarmPeriod}"&gt; 
  
          &lt;option th:each="period:${periods}" 
              th:value="${period}" th:text="${period}"&gt;
          &lt;/option&gt;&lt;/select&gt;
  </code></pre>
  
  <p>I have tried with <code>th:field="*{alarm.alarmPeriod}"</code> but the thymeleaf processor crash.</p>
  
  <p>How could I set the default value of the select with my stored entity value?</p>
  
  <p>PD: alarm is my entity and alarmPeriod is an attribute of alarm.</p>