如何显示下拉列表的某些选定值

时间:2019-02-26 17:19:07

标签: java thymeleaf

胸腺视图

 <option th:each="technology:${technology}"
  th:value="${technology}"                                     
  th:selected="${technology==project.getTechnology()}"
  th:text="${technology}"/>

Java控制器

model.addAttribute(“ technology”,organization.getTechnology());

1 个答案:

答案 0 :(得分:2)

假设您在控制器中将域绑定为import jinja2 AliasDict = {'110.34.214.180': [['SR12'], 'Unavailable', '0'], '110.34.214.110': [['SR9'], 'Unavailable', '0'], '105.34.214.184': [['SR11'], 'Available', '0'], '110.34.214.100': [['SR2'], 'Unavailable', '0'], '110.34.214.124': [['SR7'], 'Unavailable', '0'], '110.138.249.238': [['SR5'], 'Unavailable', '0'] } s = """{% for stations, value in AliasDict.items() %} {% if value[1] == 'Unavailable' %} <a href="#"> {{loop.index}}. {{stations}} : {{value[0]}}</a> {% endif %} {% endfor %} """ template = jinja2.Environment().from_string(s) data = template.render(AliasDict=AliasDict) print(data) ,并且该控制器也具有myobject作为属性。然后添加technology,您的代码将如下所示  在控制器中

th:field="*{technology}"

model.addAttribute("technology",organization.getTechnology());
model.addAttribute("myobject",new MyClass());