我正在开发一个Spring MVC应用程序,它使用Thymeleaf作为模板引擎,并且我正在尝试将显示在页面中的一些字符串大写。在我的页面上有这样的东西:
<li class="com__nav-item" th:each="menuItem : ${#authentication.principal.listaFunzioniUtente}">
<a href="" class="com__nav-link centered">
<span class="blue-line animate scaleIn delay-3" style="font-size: 1.4em; text-align: center;" th:text="${#strings.capitalize(menuItem.desFnz)}"></span>
<span class="white-circle animate scaleIn delay-5"></span>
</a>
</li>正如您在前面的代码中看到的,在第一个<span>标记中,我在menuItem对象的desFnz属性中显示了一个字符串。
它工作得很好,我的问题是我想要大写所有的字符,所以我试着这样做:
th:text="${#strings.capitalize(menuItem.desFnz)}"使用#strings.capitalize(),但它不能工作,事实上,在我的页面中,我仍然获得了文本,但没有大写。为什么?我遗漏了什么?如何解决此问题?
发布于 2016-03-16 03:02:00
#strings.capitalize(menuItem.desFnz)只会将第一个字符大写,而as #strings.toUpperCase(menuItem.desFnz)会将整个字符串转换为大写。Here is the documentation for the Strings class.
发布于 2019-04-11 17:12:16
你可以通过以下方式来完成
$string.toLowerCase()或$string.toUpperCase()
发布于 2021-05-13 05:06:19
只是补充一下帕蒂的观点。如果您在spring boot项目中使用它,其中一些值来自messages.properties
就像在messages.properties文件中一样,您具有如下内容:
email.dailyAlert.greeting.newTemplate = Dear {0},
然后,要替换{0}的值(在标题大小写中),您需要像下面这样写。
<p th:text="#{email.dailyAlert.greeting.newTemplate(${#strings.capitalize(orgSlug)})}"></p>最终输出将是:
尊敬的组织:
https://stackoverflow.com/questions/36015584
复制相似问题