title: Show Output of Controller method via Thymeleaf
body: <p>I just started working on Thymeleaf and wanted to connect a Spring Boot application with HTML using Thymeleaf. I had my &quot;normal&quot; controllers without Thymeleaf like this:</p>
  <pre><code> @GetMapping(path = &quot;/{id}&quot;)
      public BookEntity getBookById(@PathVariable Long id) {
          return bookService.getById(id);
      }
  
  
  
  @GetMapping
          public List&lt;BookEntity&gt; getAllBooks() {
              return bookService.findAll();
          }
  </code></pre>
  <p>Now that Im using Thymeleaf I created some new Controllers like this:</p>
  <pre><code> @GetMapping(path = &quot;/book/{id}&quot;)
      public String getBookById(@PathVariable(&quot;id&quot;) Long id, Model model) {
          BookEntity book= bookService.getById(id);
          model.addAttribute(&quot;book&quot;, book);
          return &quot;book/{id}&quot;;
      }
      
  @GetMapping(&quot;/book/all&quot;)
      public String AllBooks(Model model) {
          List&lt;BookEntity&gt; books = bookService.findAll();
          model.addAttribute(&quot;books&quot;, books);
  
          return &quot;books&quot;;
      }
  </code></pre>
  <p>I also created a book.html file in resources/templates like this:</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang=&quot;en&quot; xmlns:th=&quot;http://www.thymeleaf.org&quot;&gt;
  &lt;head&gt;
      &lt;meta charset=&quot;UTF-8&quot; name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0, minimum-scale=1.0&quot;&gt;
      &lt;title&gt;Books&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;h4&gt;Select action to do something&lt;/h4&gt;
  &lt;form th:action=&quot;@{/book/{id}(id=book.getId())&quot; method=&quot;get&quot;&gt;
      &lt;label for=&quot;id&quot;&gt;id:&lt;/label&gt;&lt;br&gt;
      &lt;input type=&quot;number&quot; id=&quot;id&quot; name=&quot;id&quot; placeholder=&quot;id&quot; required&gt;
      &lt;input type=&quot;submit&quot; value=&quot;Submit&quot;&gt;
  &lt;/form&gt;
  
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>But this isnt working I wanted to submit the book Id (in the input) and in return I get the Book with the right id. I tried to use ModelAndView instead of Model and return a ModelAndView but it didnt work. Can anyone tell what am I doing wrong.
  Thanks in advance</p>