如何使用Thymeleaf将数字字符串格式化为四位数。例如,5 -> 0005。
使用数字格式化字符串。具体如下:
th:text="${#numbers.formatInteger(num,5)}"
我正在使用 Thymeleaf 3.0.9,参考 Thymeleaf format。 你可以用两种方式做到这一点,
<p th:text="${#numbers.formatInteger(AccountNo,10)}"> This text will replace by AccountNo</p>
并且
<p >Hi format [[${#numbers.formatInteger(AccountNo,10)}]] </p>
账号号码的最大长度为10位。
如果您提供8位数字,则会添加两个前导零,如果长度超过最大值,则输出不会改变,即与输入相同。
例如:输入:12345678
,则输出:0012345678