首页 > 解决方案 > thymeleaf 中 String 对象的 #strings.replace() 实用程序方法是否替换了提供的字符串中的所有匹配项?

问题描述

我有一个字符串

str = My name is john.<br> I am software engineer.<br> I am a web developer<br>

我想<br><br />百里香替换所有出现的地方。

我试过这个

${#strings.replace(str,'<br>','<br />')} 

我想知道,上面的字符串替换方法是否替换所有出现的<br>

参考文献:
https ://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html
https://www.baeldung.com/spring-thymeleaf-3-expressions

标签: javahtmlspring-bootthymeleaf

解决方案


是的,它将替换所有出现的事件。Thymeleaf 内部调用 java.lang.String.replace 方法来替换出现的位置。


推荐阅读