如何使用Thymeleaf中的HashMap entrySet()选择它?

问题描述 投票:0回答:1

我尝试将selected放到空选项内,并且在th:text之后加上th:select,但对我都不起作用,这是我的代码:

<select name="uploadDate"style=" width:100%;" id="uploadDate" class="form-control select2">
        <option></option>
        <option th:each="uploadDateMenu : ${uploadDateMenu.entrySet()}"
                th:value="${uploadDateMenu.key}" 
                th:text="${uploadDateMenu.value}">
      </option>
</select>

我尝试放置代码:

th:selected="${uploadDateMenu.key == 2}"

在选项标签内的“ th:text”之后,但不起作用。数据在键值对中。密钥为2且与之对应的值为“过去2天”。

html drop-down-menu thymeleaf html-select
1个回答
0
投票

尝试:

© www.soinside.com 2019 - 2024. All rights reserved.