Thymeleaf:组合#strings 函数

Thymeleaf: combine #strings functions

是否可以这样做 th:attr="some-data=${#strings.replace(#strings.toLowerCase(object), '\s', '-')} - 如果可以,是否有更短的方法来做到这一点?谢谢

这种类型的文本操作是可能的......没有正则表达式(我认为这里正则表达式的问题是 thymleaf 转义了表达式):

"${#strings.replace(#strings.toLowerCase(object), ' ', '-')}"

如果您想设置自定义属性 'some-data' 您可以使用:

th:attr="some-data=${#strings.replace(#strings.toLowerCase(object), ' ', '-')}"

或较新版本的 tymeleaf 更短一些:

th:some-data="${#strings.replace(#strings.toLowerCase(object), ' ', '-')}