问题
I'm looking for a way to url decode a string variable on Freemarker.
For example, consider the following string: attr=hello+world%3F . Expected result: hello world?
Any simple way to get this result? somewhat like ${attr?urlDecode}? I could not find anything online.
Thanks.
回答1:
As mentioned above, FreeMarker only has built in support for URL encoding, not decoding. You can however solve this by creating your own directive for URI-decoding.
Something like this: https://gist.github.com/lazee/285d206470fb6076d262
Here is a small test class that shows you how you can add the directive as a shared variable, and how to use it in a template: https://gist.github.com/lazee/f5c524b3c7bebf68955e
回答2:
There's no such function built in (2.3.23).
In what scenario is it needed?
来源:https://stackoverflow.com/questions/32073601/is-there-any-way-to-url-decode-variable-on-freemarker