目前我在 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??。
感谢任何帮助。谢谢。
请您参考如下方法:
使用 Thymeleaf 消息表达式 (#{...}
) 时会出现 ??Something_en_US??
字符串,并且消息解析器无法解析该表达式中找到的消息代码。例如,#{foo}
需要在消息属性文件中包含一行,如下所示:
foo = Some message or text to display here
消息解析取决于 Thymeleaf 是否配置了 Spring 方言。引用文献: