Thymeleaf is a template engine created for Java-based applications. It comes with many great features and some awesome utility methods, useful in the development process. In this article, we will showcase the URI/URL utility methods used for performing operations like escaping/unescaping strings inside Thymeleaf standard expressions. The implementation of URI/URL utility methods can be found in the official Thymeleaf GitHub Repository.
If you want to learn how to construct URLs in Thymeleaf follow that link.
Allowed characters in URI path are: A-Z a-z 0-9, - . _ ~, ! $ & ' ( ) * + , ; =, @, /. Those chars will not be escaped. All other chars converted to the sequence of bytes that represents them in the specified encoding and then representing each byte in the hexadecimal representation of that byte.
Escapes the given string for use as a URL query param
3. Usage examples
In the following example we showed how to use uri escape methods.
This will produce the following output:
In this article, we presented Thymeleaf utility methods for URI/URL created to escape/unescape special characters that couldn't be used in URLs. You can use it to build safe links to articles or other resources.
Code used in this article can be found at our GitHub repository.