Thymeleaf URLs with parameters

Thymeleaf provides an easy way to create URLs using link expressions @{...}.

In this article, we will discuss how to use URLs with parameters in Thymeleaf template.

Thymeleaf URLs with parameters

To add query parameters to a URL you have to put them in parentheses ( ).
For example, one query parameter added to an URL will look like the following:

<a th:href="@{/tags(tag='thymeleaf')}">thymeleaf</a>

This will produce the following output:

<a href="/tags?tag=thymeleaf">thymeleaf</a>

Note that any special character used will be HTML-escaped.
To provide many parameters, separate them with commas:

<a th:href="@{/tags(tag='thymeleaf',order=1,sort=true)}">thymeleaf sorted</a>

Above example will be rendered like the following:

<a href="/tags?tag=thymeleaf&amp;order=1&amp;sort=true">thymeleaf sorted</a>