用thymeleaf用标签给页面select下拉框赋值怎么实现
2016-06-15 · 百度知道合伙人官方认证企业
thymeleaf用标签给页面select下拉框赋值的实现方法:
1、定义type.java
public class Type {
private Integer id;
private String type;
...getters and setters
}
2、定义SeedStarterMngController.java,将来给select的option填充值:
@ModelAttribute("allTypes")
public List<Type> populateTypes() {
Type type1 = new Type();
type1.setId(1);
type1.setType("OUTDOOR");
Type type2 = new Type();
type2.setId(2);
type2.setType("INDOOR");
List<Type> tipos = new ArrayList<Type>();
tipos.add(type1);
tipos.add(type2);
return tipos;
}
3、填充方法实现页面seedstartermng.html:
<select th:field="*{type}">
<option th:each="type : ${allTypes}" th:value="${type.id}" th:text="${type.type}">typeSelect</option>
</select>
4、实现效果:
2016-06-06 · 做真实的自己 用良心做教育
但如果paymentMethod是个以,号分隔的字符串的话,则只能自己处理了下,thymeleaf还没找到怎么整呢,我的处理方式如下:
<select multiple="multiple" class="width-40 chosen-select" name="knowledgePointIdSet" data-placeholder="请选择课件分类...">
<option th:each="category:${knowPointList}" th:value="${category.id}"
th:selected="${#strings.contains(instance.knowledgePointIdSet,category.id)}"
th:text="${category.name}" >模块名称</option>
</select>