【问题标题】:Thymeleaf: combine #strings functionsThymeleaf:结合#strings函数
【发布时间】:2019-01-12 11:56:50
【问题描述】:

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

【问题讨论】:

    标签: thymeleaf template-engine


    【解决方案1】:

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

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

    如果您想设置自定义属性“一些数据”,您可以使用:

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

    或者对于较新版本的 tymeleaf 短一点:

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

    【讨论】:

    • 哦,谢谢。我的另一个问题是我不知道我只需要使用一个th:attr 然后用逗号分隔数据。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2023-03-31
    • 2017-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多