【发布时间】:2014-10-06 07:49:52
【问题描述】:
目前我在 Spring MVC 中有此代码来填充所有选项,例如“Doctor”等...
@ModelAttribute("allTypes")
public List<String> populateType() {
String a[]= new String[]{"Doctor","Patient"};
return Arrays.asList(a);
}
而这段代码在 HTML 中,它使用上面的代码来显示下拉列表中的选项。
<select th:field="*{type}">
<option value="NONE">------Select-------</option>
<option th:each="type:${allTypes}" th:value="${type}" th:text="#{${type}}"></option>
</select>
我遇到的问题是下拉列表中有奇怪的输出。例如 ??Doctor_en_US??, ??Patient_en_US??。
感谢任何帮助。谢谢。
【问题讨论】:
-
您的国际化配置似乎有问题
-
我刚刚意识到我在 th:text 处犯了一个错误,它应该与 th:value 相同,现在它正在显示正确的值。
-
我强烈建议不要使用数组(在这种情况下,您可以使用
Arrays.asList("Doctor", "Patient"))和变量名称,例如a。只是我的两分钱。
标签: java html spring thymeleaf