Thymeleaf send parameter from html to controller

You do not need form to do this:

<td>
    <a th:href="@{'/users/doDelete/' + ${user.id}}">
        <span>Delete</span>
    </a>
</td>


Blejzer answer is an easy and straight forward solution unless you are also working with spring security (always recommended) in which case you should prefer POST instead of GET for all modification operations such as delete to protect against CSRF attack. This is exactly why spring recommends logout be done like this only. In order for you to adapt to POST, change your controller to read this parameter from request parameters instead of path variable

//delete user
@RequestMapping(value="users/doDelete", method = RequestMethod.POST)
public String deleteUser (@RequestParam Long id) {
    customerDAO.delete(id);
    return "redirect:/users";
}

Add a hidden field in the form which posts with the id as name and it's value in hidden parameter

<form th:action="@{/users/doDelete}" th:object="${customer}" method="post">
    <input type="hidden" th:field="${id}" />
    <button type="submit">Delete</button>
</form>

On a side note, even if you are not using spring security, it is always recommended to use post for any entity modification operations (like delete or update). Saves you from lots of trouble on web in long run. Take a look at Quick Checklist for Choosing HTTP GET or POST for detailed information.


path variables can be set as:

<a th:href="@{/users/doDelete/__${user.id}__}"><span>Delete</span></a>