Spring mvc 在Thymeleaf的下拉列表中使用HashMap

Spring mvc 在Thymeleaf的下拉列表中使用HashMap,spring-mvc,thymeleaf,Spring Mvc,Thymeleaf,在我的控制器中,我正在设置哈希映射 @ModelAttribute("clientImpMap") public Map<String,String> populateClientImpMap() throws MalformedURLException, IOException { Map<String,String> clientImpMap = new HashMap<String,String> (); clientImpMap.p

在我的控制器中,我正在设置哈希映射

@ModelAttribute("clientImpMap")
public Map<String,String> populateClientImpMap() throws MalformedURLException, IOException 
{

    Map<String,String> clientImpMap = new HashMap<String,String> ();
    clientImpMap.put("1","High");
    clientImpMap.put("2","Low");
    return clientImpMap;
}
@modeldattribute(“clientImpMap”)
public Map populateClientImpMap()引发MalformedURLException,IOException
{
Map clientImpMap=newhashmap();
clientImpMap.put(“1”、“高”);
clientImpMap.put(“2”,“低”);
返回clientmpmap;
}
现在我想用Thymeleaf标签填充这个hashmap。怎么做? 使用核心Spring mvc标记,我可以做到这一点

<td>Client Importance :</td>
    <td><form:select path="personBean.clientImpRef">
            <form:option value="NONE" label="--- Select ---" />
            <form:options items="${clientImpMap}"  />
        </form:select></td>
    <td><form:errors path="personBean.clientImpRef" cssClass="error" /></td>
</tr>
客户重要性:

在thymeleaf中,这与什么是等价的?

下面的代码对应于您在问题中发布的带有spring标记的jsp

<form action="your-controller-mapping" th:object="${personBean}">
   <select th:field="*{clientImpRef}">
      <option value="NONE">----Select----</option>
      <option th:each="entry : ${clientImpMap.entrySet()}" th:value="${entry.key}" th:text="${entry.value}">
        This will be replaced - is only used for natural templating
      </option>
   </select>
</form>

----挑选----
这将被替换-仅用于自然模板

以下是示例代码和链接

th:each="item : ${items}" th:text="${item.description}"

  • 此处的项目说明

我不太确定您想做什么,但以下代码是否符合要求<代码>如果是,请告诉我,以便我可以添加它作为答案。如果没有,你应该在你的问题上发布更多的细节什么是
clientImpRef
这里?@JavaTechnical这是Person字段的名称bean@geoand我正在做同样的事情,但在提交按钮后,它会打印错误。你能帮我吗?请检查如何设置答案的格式。您可以使用代码高亮显示之类的内容,越多地解释为什么这个答案有效,效果越好。这里有一个关于如何格式化的链接
<ul>
  <li th:each="item : ${items}" th:text="${item.description}">Item description here...</li>
</ul>