我需要使用字符串列表中的所有值填充下拉列表.
控制器类
@RequestMapping(value = "/generateIds", method = RequestMethod.GET)
public String launchPage(Model model) {
List<Municipality> municipalities = rCountryService.finaAllMunicipalities();
//assume the list is populated with values
List<String> countryName = new ArrayList<String>();
for(int i=0; i<municipalities.size(); i++) {
countryName.add(municipalities.get(i).getCountry().toString());
}
model.addAttribute("countryName ", countryName );
return "generateIds";
}
Run Code Online (Sandbox Code Playgroud)
我不知道从哪里开始HTML,所以我从这开始
<select th:field="*{countryName }">
<option value="default">Select a country</option>
<option th:each="${countryName }" th:value="${countryName }"th:text="${countryName }"/>
</select>
Run Code Online (Sandbox Code Playgroud)
我的html/controller应该如何将列表中的所有元素添加为下拉选项?
提前致谢!