Im using thymeleaf with spring mvc. I want add a language param to change locale. I did it this way:
<a th:href="@{${currentUrl}(lang='es_ES')}" th:if="__${#locale}__ != 'es_ES'" >Sp</a>
<a th:href="@{${currentUrl}(lang='en_US')}" th:if="__${#locale}__ != 'en_US'" >Eng</a>
But in some views I have params in the URL. How I can add the parameters? I know how to add when I meet the specific parameter:
<a th:href="@{${currentUrl}(fooParam = ${fooValue}, lang='es_ES')}" th:if="__${#locale}__ != 'es_ES'" >Sp</a>
But I know neither the number and name of all parameters in all views. How I can get all the parameters of the current url?
You can try to create an utility service for building the params part of your URL. The utility method will get input from a List and build a String through StringBuffer. The result will be a String written as when you write param manually. Now you can use the Pre-Parser syntax built in thymeleaf to call the utility and build your final url. Here the example:
Utility Service
Controller for testing it
HtmlTemplate for Test:
this is what you get with the example:
You can now customize this example to suit your code, like parsing a Map instead of List or String...