【问题标题】:Thymeleaf - adding a part of a class name to classappendThymeleaf - 将类名的一部分添加到 classappend
【发布时间】:2017-09-21 11:29:50
【问题描述】:

我正在将我的应用程序从 JSP 移植到 Thymeleaf,我在尝试使用 classappend 时发现了一些问题

如果操作完成,我有一个 div 元素,无论是好是坏,我通常都会在我的控制器中添加一个 $css 值以附加到 div 类。 我不能在 Thymeleaf 中做到这一点......我正在尝试这种方式

<div th:classappend="${css != null} ? alert alert-${css} alert-dismissible"
                            th:text="${msg != null} ? ${msg}">
                            <button title="close" type="button" class="close"
                                data-dismiss="alert" aria-label="Close" aria-hidden="true">
                                x</button>
                            <strong th:text="${msg}"></strong>

                        </div>

${css} 可能是危险或成功或任何其他 Bootstrap 文本类...

我来了

Could not parse as expression: \"${css != null} ? alert alert-${css} alert-dismissible\

这有什么问题?

【问题讨论】:

    标签: css spring-boot thymeleaf


    【解决方案1】:

    这是你的字符串连接:

    <div th:classappend="*{css} ? 'alert alert-'+${css}+' alert-dismissable' : ''" th:text="*{msg} ? ${msg}: ''">
            <button title="close" type="button" class="close"
                    data-dismiss="alert" aria-label="Close" aria-hidden="true">x</button>
            <strong th:text="${msg}"></strong>
    </div>
    

    【讨论】:

    • 谢谢,不是第三个元素的问题,而是字符串连接的问题!改变你的答案,让我接受!!
    猜你喜欢
    • 2010-11-16
    • 2020-06-14
    • 2020-04-13
    • 2016-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多