How can I capitalize a string showed by Thymeleaf into a page?

非 Y 不嫁゛ 提交于 2019-12-10 13:06:19

问题


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>

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)}"

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?


回答1:


#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.




回答2:


you can do it by

$string.toLowerCase() or $string.toUpperCase()



来源:https://stackoverflow.com/questions/36015584/how-can-i-capitalize-a-string-showed-by-thymeleaf-into-a-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!