title: how to pass parameter from HTML with Thymeleaf to Spring Controller?
body: <p>I have a controller in Spring Boot that needs to recieve a parameter and an object by POST. The parameter is NOT an object or part of if. </p>
  
  <p>Here is the Thymeleaf form without the parameter. It works fine in a stand-alone page, but the same code does not work when I use it in a page that shows an article:</p>
  
  <pre><code>&lt;form th:action="@{/addcomment}" th:object="${comment}" method="post"&gt;
      &lt;input type="text" th:field="*{commenttext}" /&gt;
      &lt;button type="submit"&gt;send&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>because when I add the </p>
  
  <pre><code>&lt;input type="hidden" th:field="*{id}" th:with="id=1" value="${id}"/&gt;
  </code></pre>
  
  <p>or</p>
  
  <pre><code>&lt;input type="hidden" th:field="*{id}"/&gt;
  </code></pre>
  
  <p>or</p>
  
  <pre><code>&lt;input type="hidden" th:field="*{id}" value="1"/&gt;
  </code></pre>
  
  <p>my Controller prints 0 in the console, when the value should be 1... (and even if I change it to value="true".... this comes from the Chrome console:</p>
  
  <pre><code>&lt;input type="hidden" class="sr-only" value="0" id="id" name="id" /&gt;
  </code></pre>
  
  <p>no matter what I use</p>
  
  <pre><code>@RequestMapping(value = "/addcomment", method = RequestMethod.POST)
  ModelAndView addStatus(ModelAndView modelAndView, @Valid Comment comment, @RequestParam("id") Long id, BindingResult result) {
  
      Comment commentform = new Comment();
  
      Announcement announcement = announcementService.readAnnouncement(id);
  
      String sanatizedcommenttext = htmlPolicy.sanitize(comment.getCommenttext());
      commentform.setCommenttext(sanatizedcommenttext);
      commentform.setDate(new Date());
      commentform.setAnnoucements(announcement);
  
      modelAndView.setViewName("addcomment");
  
      if (!result.hasErrors()) {
          commentService.createComment(commentform);
  
          modelAndView.getModel().put("comment2th", new Comment());
          modelAndView.setViewName("redirect:/addcomment");
      }
  
      return modelAndView;
  }
  </code></pre>
  
  <p>By the way, the parameter is in the url (but I would like to know how to send it to the controller independently of where it is located).
  thanks for your help!</p>