首页 > 解决方案 > 尝试以百里香叶形式填充复选框时无法解析为表达式

问题描述

我正在尝试从 spring boot 返回的模型对象中填充 thymeleaf html 表单中的值,下面是代码。instance 是主要对象,它包含一个数组,channel,包含 [web, corp, mobile] 之类的值

<div th:object = "${instance}">

<div class="control-group">
        <label class="control-label"  >Applicable on</label>
        <div class="controls">
            <label class="checkbox inline">
            <input class="input-style" type="checkbox" value="web" id="channel1" name="channel" th:checked="${(instance.channel.contains("web")
            )}">
            web
            </label>
            <label class="checkbox inline">
                <input class="input-style" type="checkbox" value="corp" id="channel2" name="channel" th:checked="${(instance.channel.contains("corp")
                )}">
                corp
            </label>
            <label class="checkbox inline">
                <input class="input-style" type="checkbox" value="mobile" id="channel3" name="channel" th:checked="${(instance.channel.contains("mobile")
                )}">
                mobile
            </label>
        </div>
    </div>

运行应用程序时,出现以下错误

Cannot render error page for request [/5cdaabf9d7d4ae55db7ad1ae] and exception [Could not parse as expression: "${(instance.channel.contains(" (template: "editFilter" - line 199, col 94)] as the response has already been committed. As a result, the response may have the wrong status code

有人可以帮我解决如何从数组中修复和填充表单中的复选框吗?

标签: htmlspring-bootcheckboxthymeleaf

解决方案


推荐阅读