如何将 Thymeleaf 显示的字符串大写到页面中? [英] How can I capitalize a string showed by Thymeleaf into a page?
问题描述
我正在开发一个使用 Thymeleaf 作为模板引擎的 Spring MVC 应用程序,我正在尝试将一些显示在我的页面中的字符串大写.在我的页面上,我有这样的东西:
I am working on a Spring MVC application that uses Thymeleaf as template engine and I am trying to capitalize some string showed into my page. On my page I have something like this:
<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>
正如您在前面的代码中看到的,在第一个 标记中,我在
menuItem<的
desFnz
属性中显示了一个字符串/code> 对象.
As you can see in the previous code, in the first <span>
tag, I show a string inside the desFnz
property of the menuItem
object.
它工作正常,我的问题是我想大写所有字符,所以我尝试这样做:
It works fine, my problem is that I want capitalize all the characters, so I tried to do:
th:text="${#strings.capitalize(menuItem.desFnz)}"
使用 #strings.capitalize()
但它无法工作,实际上在我的页面中我仍然获得文本但没有大写.为什么?我错过了什么?我该如何解决这个问题?
using the #strings.capitalize()
but it can't work, in fact in my page I still obtain the text but not capitalized. Why? What am I missing? How can I fix this issue?
推荐答案
#strings.capitalize(menuItem.desFnz)
只会将第一个字符大写,其中 #strings.toUpperCase(menuItem.desFnz)
将整个字符串转换为大写.这里是 Strings 类的文档.一个>
#strings.capitalize(menuItem.desFnz)
will only capitalize the 1st character, where as #strings.toUpperCase(menuItem.desFnz)
will convert the entire string to uppercase. Here is the documentation for the Strings class.
这篇关于如何将 Thymeleaf 显示的字符串大写到页面中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!