thymeleaf #{} i18n 传递参数

it2024-01-30  63

thymeleaf #{} i18n 传递参数

i18n的properties配置文件里如下定义:

file_download_url = https://www.baidu.com_{0}_{1}.html

html页面使用:

<a th:href="#{file_download_url (${#numbers.formatInteger(1111, 1)}, 'abc')}" target="_blank" th:text="${item.fileName}">附件名称</a>

生成的链接:https://www.baidu.com_1111_abc.html

需要注意的是如果参数是数字类型且超过四位需要用#numbers.formatInteger() 工具类转一下,否则会当成字符串处理。如:1,111

最新回复(0)