如何使用百里香和春天填充下拉列表 [英] How do I populate a drop down with a list using thymeleaf and spring

查看:126
本文介绍了如何使用百里香和春天填充下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



控制器类



pre> @RequestMapping(value =/ generateIds,method = RequestMethod.GET)
public String launchPage(Model model){
List< Municipality>自治市= rCountryService.finaAllMunicipalities();
//假定列表中填充了值
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);

返回generateIds;
}

我不知道从哪里开始,所以我开始使用这个

 < select th:field =* {countryName}> 
< option value =default>选择国家< / option>
< option th:each =$ {countryName}th:value =$ {countryName}th:text =$ {countryName}/>
< / select>

我的html / controller应该如何将列表的所有元素添加为下拉选项?



预先感谢!

解决方案

下拉列表。我认为这可能有助于你对此有所了解。



控制器

 列表与LT;操作> operators = operatorService.getAllOperaors()
model.addAttribute(operators,operators);

模型

  @Entity 
@Table(name =operator)
public class Operator {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name =id)
@JsonIgnore
私人长ID;

@NotBlank(message =operator Name can not be empty)
@Column(name =operator_name,nullable = false)
private String operatorName;

getters and setters ...

}

查看

 < div class =form-group blu-margin> 
发送“验证码”获取 | 15天全站免登陆