title: Update Entity via HTML
body: <p>I would like to update an entity in a repository. The thing is that I do not know how to get the id from the entity being changed, that's why I am not able to change it correctly.</p>
  <p>The form works smooth when it comes to change specified Id of an entity. Form is visible and I can change the values. But how exactly change these values (dates) in an entity, specified by Id?</p>
  <p>Can You guys help me with this?</p>
  <p>HomeController class:</p>
  <pre><code>@Controller
  
  public class HomeController {
  
  @Autowired
  private PropertyRepository propertyRepository;
  
  @Autowired
  private PropertyService propertyService;
  
  private final String title = &quot;Obiekty do wynajęcia&quot;;
  
  public List&lt;Property&gt; findByKeyword(String keyword) {
      return propertyRepository.findByKeyword(keyword);
  }
  
  
  @GetMapping(&quot;/&quot;)
  public String index(Model model, String keyword) {
  
  
      model.addAttribute(&quot;title&quot;, title);
      model.addAttribute(&quot;properties&quot;, propertyRepository.findAll());
  
      if (keyword != null) {
          model.addAttribute(&quot;properties&quot;, propertyRepository.findByKeyword(keyword));
      } else {
          model.addAttribute(&quot;title&quot;, title);
          model.addAttribute(&quot;properties&quot;, propertyRepository.findAll());
      }
      return &quot;index&quot;;
  }
  
  @GetMapping(&quot;/property/change/{id}&quot;)
  public String changePropertyForm(@PathVariable(&quot;id&quot;) int id, Model model) {
      model.addAttribute(&quot;properties&quot;, propertyRepository.findById(id).get());
      return &quot;change&quot;;
  }
  
  @PostMapping(&quot;/change_submit&quot;)
  public void submitChange(@PathVariable int id, Property property) {
  
      propertyService.UpdatePropertyDates(id, property);
  }
  }
  </code></pre>
  <p>Service class:</p>
  <pre><code>@Service
  public class PropertyService {
  
  @Autowired
  PropertyRepository propertyRepository;
  
  public void UpdatePropertyDates(int id, Property property) {
  
      Property previousProperty = propertyRepository.findById(id).get();
      previousProperty.setReservationStartDate(previousProperty.getReservationStartDate());
      previousProperty.setReservationEndDate(property.getReservationEndDate());
      propertyRepository.save(previousProperty);
  }
  }
  </code></pre>
  <p>Index.html:</p>
  <pre><code>    &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
          &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
  &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot; xmlns:font-size=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
  &lt;head&gt;
      &lt;title&gt;Baza obiektów do wynajęcia&lt;/title&gt;
      &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;/&gt;
  
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div style=&quot;text.align: center&quot;&gt;
      &lt;h3&gt;&lt;a href=&quot;/submit&quot;&gt;Dodaj obiekt do bazy&lt;/a&gt;&lt;/h3&gt; &lt;br/&gt; &lt;br/&gt;
  &lt;/div&gt;
  &lt;h2&gt;Baza obiektów&lt;/h2&gt;
  
  &lt;div class=&quot;container&quot; style=&quot;text-align: left&quot;&gt;
      &lt;div&gt;
          &lt;form th:action=&quot;@{/}&quot; method=&quot;get&quot;&gt;
              Filter: &lt;input id=&quot;txtSearch&quot; type=&quot;text&quot; name=&quot;keyword&quot;/&gt;
              &amp;nbsp;
              &lt;input type=&quot;submit&quot; value=&quot;Search&quot;/&gt;
              &amp;nbsp;
              &lt;button onclick=&quot;document.getElementById('txtSearch').value = ''&quot;&gt;Clear&lt;/button&gt;
          &lt;/form&gt;
      &lt;/div&gt;
      &lt;table&gt;
          &lt;thead&gt;
          &lt;th&gt;&lt;b&gt;Name of a property&lt;/b&gt;&lt;/th&gt;
          &lt;th&gt;&lt;b&gt;Name of a property owner&lt;/b&gt;&lt;/th&gt;
          &lt;th&gt;&lt;b&gt;Start of reservation&lt;/b&gt;&lt;/th&gt;
          &lt;th&gt;&lt;b&gt;End of reservation&lt;/b&gt;&lt;/th&gt;
          &lt;th&gt;&lt;b&gt;Actions&lt;/b&gt;&lt;/th&gt;
          &lt;/thead&gt;
          &lt;tbody&gt;
          &lt;tr th:each=&quot;property : ${properties}&quot;&gt;
              &lt;td th:text=&quot;${property.propertyName}&quot;&gt;&lt;/td&gt;
              &lt;td th:text=&quot;${property.landlordName}&quot;&gt;&lt;/td&gt;
              &lt;td th:text=&quot;${property.reservationStartDate}&quot;&gt;&lt;/td&gt;
              &lt;td th:text=&quot;${property.reservationEndDate}&quot;&gt;&lt;/td&gt;
              &lt;td&gt;
                  &lt;a th:href=&quot;|/property/change/${property.id}|&quot;&gt;Zmień&lt;/a&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;/tbody&gt;
      &lt;/table&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>Change.html:</p>
  <pre><code>    &lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
          &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
  &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
  &lt;head&gt;
      &lt;title&gt;Zmień rezerwację&lt;/title&gt;
      &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot;/&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div class=&quot;container&quot;&gt;
      &lt;h3&gt;Rezerwacja numer: &lt;span th:text=&quot;${properties.id}&quot;&gt;&lt;/span&gt;&lt;/h3&gt;
      &lt;div&gt;
          &lt;p&gt;Nazwa obiektu: &lt;span th:text=&quot;${properties.propertyName}&quot;&gt;&lt;/span&gt;&lt;/p&gt;
          &lt;p&gt;Imię właściciela: &lt;span th:text=&quot;${properties.landlordName}&quot;&gt;&lt;/span&gt;&lt;/p&gt;
          &lt;p&gt;Początek rezerwacji: &lt;span th:text=&quot;${properties.reservationStartDate}&quot;&gt;&lt;/span&gt;&lt;/p&gt;
          &lt;p&gt;Koniec rezerwacji: &lt;span th:text=&quot;${properties.reservationEndDate}&quot;&gt;&lt;/span&gt;&lt;/p&gt;
      &lt;/div&gt;
      &lt;form th:action=&quot;@{/change_submit}&quot; method=&quot;post&quot;
            style=&quot;max-width: 600px; margin: 0 auto;&quot;
            th:object=&quot;${properties}&quot;&gt;
          &lt;div class=&quot;m-3&quot;&gt;
              &lt;div class=&quot;form-group row&quot;&gt;
                  &lt;label class=&quot;col-form-label col-4&quot;&gt;Zmiana nazwy obiektu&lt;/label&gt;
                  &lt;div class=&quot;col-8&quot;&gt;
                      &lt;input type=&quot;text&quot; class=&quot;form-control&quot; th:field=&quot;*{propertyName}&quot; required/&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class=&quot;m-3&quot;&gt;
              &lt;div class=&quot;form-group row&quot;&gt;
                  &lt;label class=&quot;col-form-label col-4&quot;&gt;Zmiana imienia właściciela&lt;/label&gt;
                  &lt;div class=&quot;col-8&quot;&gt;
                      &lt;input type=&quot;text&quot; class=&quot;form-control&quot; th:field=&quot;*{landlordName}&quot; required/&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class=&quot;m-3&quot;&gt;
              &lt;div class=&quot;form-group row&quot;&gt;
                  &lt;label class=&quot;col-form-label col-4&quot;&gt;Zmień początek rezerwacji (dd-mm-yyyy)&lt;/label&gt;
                  &lt;div class=&quot;col-8&quot;&gt;
                      &lt;input class=&quot;form-control&quot; pattern=&quot;\d{2}-\d{2}-\d{4}&quot; th:field=&quot;*{reservationStartDate}&quot; required/&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class=&quot;m-3&quot;&gt;
              &lt;div class=&quot;form-group row&quot;&gt;
                  &lt;label class=&quot;col-form-label col-4&quot;&gt;Zmień koniec rezerwacji (dd-mm-yyyy)&lt;/label&gt;
                  &lt;div class=&quot;col-8&quot;&gt;
                      &lt;input class=&quot;form-control&quot;pattern=&quot;\d{2}-\d{2}-\d{4}&quot; th:field=&quot;*{reservationEndDate}&quot; required/&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div&gt;
                  &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot;&gt;Zmień&lt;/button&gt;
                  &lt;input type=&quot;reset&quot;&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/form&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>And my pom.xml</p>
  <pre><code>    &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
           xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;parent&gt;
          &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
          &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt;
          &lt;version&gt;2.5.6&lt;/version&gt;
          &lt;relativePath/&gt; &lt;!-- lookup parent from repository --&gt;
      &lt;/parent&gt;
      &lt;groupId&gt;com.example&lt;/groupId&gt;
      &lt;artifactId&gt;propertyBase&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;propertyBase&lt;/name&gt;
      &lt;description&gt;Add Your property!&lt;/description&gt;
      &lt;properties&gt;
          &lt;java.version&gt;11&lt;/java.version&gt;
      &lt;/properties&gt;
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-jdbc&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;
          &lt;/dependency&gt;
  
          &lt;dependency&gt;
              &lt;groupId&gt;javax.xml.bind&lt;/groupId&gt;
              &lt;artifactId&gt;jaxb-api&lt;/artifactId&gt;
              &lt;version&gt;2.3.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.thymeleaf&lt;/groupId&gt;
              &lt;artifactId&gt;thymeleaf&lt;/artifactId&gt;
              &lt;version&gt;3.0.15.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.h2database&lt;/groupId&gt;
              &lt;artifactId&gt;h2&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.webjars&lt;/groupId&gt;
              &lt;artifactId&gt;bootstrap&lt;/artifactId&gt;
              &lt;version&gt;4.3.1&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.webjars&lt;/groupId&gt;
              &lt;artifactId&gt;webjars-locator-core&lt;/artifactId&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;mysql&lt;/groupId&gt;
              &lt;artifactId&gt;mysql-connector-java&lt;/artifactId&gt;
              &lt;scope&gt;runtime&lt;/scope&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
              &lt;artifactId&gt;lombok&lt;/artifactId&gt;
              &lt;optional&gt;true&lt;/optional&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-thymeleaf&lt;/artifactId&gt;
              &lt;version&gt;2.3.3.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;com.github.joutvhu&lt;/groupId&gt;
              &lt;artifactId&gt;spring-dynamic-jpa&lt;/artifactId&gt;
              &lt;version&gt;2.3.3&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-test&lt;/artifactId&gt;
              &lt;scope&gt;test&lt;/scope&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
                  &lt;artifactId&gt;spring-boot-maven-plugin&lt;/artifactId&gt;
                  &lt;configuration&gt;
                      &lt;excludes&gt;
                          &lt;exclude&gt;
                              &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;
                              &lt;artifactId&gt;lombok&lt;/artifactId&gt;
                          &lt;/exclude&gt;
                      &lt;/excludes&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
  &lt;/project&gt;
  </code></pre>