【问题标题】:Weird ?? en_US?? appearing in options tag诡异的 ?? en_US??出现在选项标签中
【发布时间】: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


【解决方案1】:

??Something_en_US?? 字符串在使用 Thymeleaf 消息表达式 (#{...}) 时出现,并且消息解析器无法解析在该表达式中找到的消息代码。例如,#{foo} 需要在消息属性文件中包含如下内容:

foo = Some message or text to display here

消息解析取决于 Thymeleaf 是否配置了 Spring 方言。参考资料:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-04-03
    • 1970-01-01
    • 1970-01-01
    • 2018-04-18
    • 1970-01-01
    • 2012-01-06
    • 1970-01-01
    • 2013-07-17
    相关资源
    最近更新 更多