Is there any way to url decode variable on Freemarker?

孤街醉人 提交于 2019-12-08 11:21:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!