Java 如何使用spring和thymeleaf在Hashmap中获取发布的值?

Java 如何使用spring和thymeleaf在Hashmap中获取发布的值?,java,spring,thymeleaf,Java,Spring,Thymeleaf,你好 我正试图通过Hashmap显示select字段选项,并获取发布的值 我使用两个类,一个是控制器类,另一个是模型类 public class MyForm { private int id; private Map<String, String> list; //getter setters } @Controller public class MyController { @GetMapping("/create") public String s

你好

我正试图通过Hashmap显示select字段选项,并获取发布的值

我使用两个类,一个是控制器类,另一个是模型类

public class MyForm {
   private int id;
   private Map<String, String> list;
   //getter setters
}

@Controller
public class MyController {

  @GetMapping("/create")
  public String showForm(MyForm myForm) {
    Map<String, String> list = new HashMap();
    list.put("US", "United States")
    list.put("UK", "United Kingdom")
    return "myview"
  }


  @PostMapping("/create")
  @ResponseBody
  public String showForm(MyForm myForm) {

    return "id: " + myform.getId() + " list: " + myform.getList();
  }

}
请帮我做这件事

谢谢。

没关系

我通过添加额外的字段来完成

List<String> country;
列出国家;
在MyForm模型类中,并将名称国家/地区分配给thymeleaf中的选择字段

<select id="country" name="country">
<option th:each="c : *{list}" th:value="${c.key}" th:text="${c.value}"></option>
</select>

List<String> country;
<select id="country" name="country">
<option th:each="c : *{list}" th:value="${c.key}" th:text="${c.value}"></option>
</select>