小编Rom*_*cci的帖子

如何使用百日咳和弹簧填充下拉列表

我需要使用字符串列表中的所有值填充下拉列表.

控制器类

@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应该如何将列表中的所有元素添加为下拉选项?

提前致谢!

html java spring thymeleaf

14
推荐指数
3
解决办法
4万
查看次数

标签 统计

html ×1

java ×1

spring ×1

thymeleaf ×1