Freemarker 如何通过后端发送 UI 上的 select 复选框?

Freemarker how to select checkboxes on UI send by backend?

从后端传递了以下数据:

ALL_CONFIGS: {callDigitalIo=true, controllerId=1, numberPlatesHashSalt=..., numberPlatesShouldBeHashed=false, parkingStatusShouldBeChecked=true}

其中 boolean params 应该像带有 type=checkbox.

input 元素一样显示

以下是我在 UI 页面 (.ftl) 上的处理方式:

<div>
    <label class="col-form-label">
        Parking Status Should Be Checked:
        <input type="checkbox" class="form-check-input ml-2"
               id="parkingStatusShouldBeChecked" name="parkingStatusShouldBeChecked"
               <#if parkingStatusShouldBeChecked??>checked="checked"</#if>
        />
    </label>
</div>

但是,复选框都是 selected:

Number Plates Should be Hashed 不应 selected。

如何select只有true个变量?

经过大量研究,我找到了解决此问题的方法:

<div>
    <label class="col-form-label">
        Parking Status Should Be Checked:
        <input type="checkbox" class="form-check-input ml-2"
               id="parkingStatusShouldBeChecked"
               <#if parkingStatusShouldBeChecked == "true">checked</#if>
        />
    </label>
</div>

它工作正常。