简体   繁体   English

字符串格式Thymeleaf Spring Boot

[英]String Format Thymeleaf Spring Boot

I using thymeleaf and spring boot to build my web application. 我使用thymeleaf和spring boot来构建我的Web应用程序。
I have problem on internationalization. 我对国际化有疑问。
I need to change all text on my web application into outer file based (all text include validation). 我需要将Web应用程序上的所有文本更改为基于外部文件(所有文本包括验证)。
I have code like this: 我有这样的代码:

error.required=The {0} is required error.required = {0}是必需的

My web application have 2 validation. 我的Web应用程序有2个验证。
Validation from modal warning and validation from javascript for bootstrapvalidator. 来自模式警告的验证和来自Javascript的bootstrapvalidator的验证。
For javascript, it work fine after I implement JavaScript equivalent to printf/string.format 对于javascript,在实现与printf / string.format等效的JavaScript后,它可以正常工作
But my problem is on thymeleaf. 但是我的问题出在百里香。
My question: How do I inject {0} from (The {0} is required) with another string? 我的问题:如何从另一个字符串中注入{0}(必须是{0})?

NB: I have tried to do something like this but the result is error 注意:我试图做这样的事情,但结果是错误

<p th:text="string.format(#{error.required}, #{label.name})"></p>

Using Thymeleaf to insert a property string inside another one defined with one or more parameters, the construction follows this format: 使用Thymeleaf在另一个由一个或多个参数定义的字符串中插入属性字符串,该构造遵循以下格式:

#{multiplestr.parameters(#{text.param1},#{text.param2})}

In this case, to insert #{label.name} in {0} inside the error.required text: 在这种情况下,要将#{label.name}插入错误中的{0}内,必填文本:

#{error.required(#{label.name})}

Messages in Thymeleaf Thymeleaf中的消息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM