添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
深情的山寨机  ·  External name not ...·  1 年前    · 
含蓄的罐头  ·  javascript - ...·  1 年前    · 

springboot国际化占位符

Spring Boot支持国际化,可以通过使用占位符的方式实现。占位符是一个用于表示变量的字符,你可以在国际化资源文件中使用占位符。

首先需要在application.properties或application.yml中配置国际化相关信息,如:

spring.messages.basename=i18n/messages
spring.messages.encoding=UTF-8

然后创建国际化资源文件,如:i18n/messages_zh_CN.properties和i18n/messages_en_US.properties

在资源文件中定义占位符,如:

welcome=欢迎您! {0}

最后在代码中使用占位符,如:

@Value("${welcome}")
private String welcome;

使用时传入参数:

String message = MessageFormat.format(welcome, "ChatGPT");

这样就可以实现国际化占位符的使用了。

  •