![](/img/trans.png)
[英]Safely pass strings from Java .properties file to a string processed by JavaScript
[英]Is there a way to add variables into strings from string.properties file?
我被告知將應用程序所需的所有字符串存儲在 .properties(以便將來的應用程序本地化更容易維護)文件中,我這樣做了現在我必須更改其中的一些,以便它們在其中包含一些變量,例如字符串“嘿,你有一條新消息”現在應該是“嘿,你有一條來自”的新消息,並且該字符串仍應存儲在 .properties 文件中
我現在所擁有的:
@Configuration
@ConfigurationProperties(prefix = "fcm.msg")
@PropertySource("classpath:notification.properties")
class FCMConfig {
lateinit var newMessageBody: String
這是方法-
將字符串數據存儲在屬性文件中
new-message-body = "Hey, you have a new message"
那么你想在哪里使用那個字符串然后就用這個
@Value("${new-message-body}")
private String message;
然后您可以在該類中的任何位置使用 message 變量。
如果你不想創建任何變量,那么就
System.out.println(@Value("${new-message-body}"));
在 kotlin 中你可以這樣做
var variable_name:String=getString(R.string.newMessageBody)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.