1. Problem
In this short Q&A article, we are going to show how to get URL request parameters in Thymeleaf template view.
2. Solution
Luckily, request parameters can be easily accessed in Thymeleaf views using built-in tools.
For request parameters like in the following URL:
In order to access query
parameter we could use the param
object:
Another way to access URL parameters is by using the special #request
object that gives you direct access to the javax.servlet.http.HttpServletRequest
class:
Note that parameters could be multivalued like in the following example:
In this case we need to use an index of the array:
To iterate over array we could use th:each
attribute.
{{ 'Comments (%count%)' | trans {count:count} }}
{{ 'Comments are closed.' | trans }}