消息属性文件
java中是否有相当于org.springframework.context.support.ResourceBundleMessageSource包的VB?
我这个问题的重点不是Spring。我想知道是否有一种方法可以拥有一个消息属性文件,我可以像使用 hat java 包一样传递变量。
这是我想做的一个例子。
在属性文件中具有以下行:
success.message = Successfully created document with Trans No. {0}
在源代码中具有以下行:
ResourceBundleMessageSource.getMessage("success.message",new String[] {transObject.getTransId()}, null));
此代码使用属性文件查找 success.message 并从 getTransId() 传递变量。
我想这样做以集中所有我的错误消息。并且在我的代码中没有硬编码消息。
VB中有某种等价的东西吗?
Is there a VB equivalent to org.springframework.context.support.ResourceBundleMessageSource package in java?
I am not focusing on Spring with this question. I want to know if there is a way to have a message properties file that I can pass variables like you can with hat java package.
Here is an example of what I would like to do.
In a properties file have the following line:
success.message = Successfully created document with Trans No. {0}
In source code have this line:
ResourceBundleMessageSource.getMessage("success.message",new String[] {transObject.getTransId()}, null));
This code uses the properties file finds success.message and passes the variable from getTransId().
I want to do this to centralize all my error messages. and not have hard coded messages throughout my code.
Is there some kind of equivalent in VB?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种解决方案是使用资源文件。通过右键单击项目并选择项目属性来添加资源。然后单击资源并添加新资源。
我们从问题中的例子开始工作:
对于资源,我们不能遵循如上所示的相同命名约定。我们需要替换“.”带“_”即: success.message ->成功消息
资源文件不允许使用“.”在键名称中。
接下来我们需要将消息写入资源文件中。
“{0}已成功提交文件。”
我们使用 {0}....{x} 作为变量的占位符。
资源选项卡中的第一行应如下所示
替换占位符的函数应如下所示:
现在,在代码中,您所要做的就是调用此函数并传递资源和变量的字符串数组。
那应该可以解决问题。
我使用此作为编译此信息的资源。
One solution is to use resource files. Add a resource by right clicking on the project and selecting project properties. Then click on resources, and add a new resource.
We work from the example in the question :
With resources we cannot follow the sam naming convention as you see above. We need to replace the '.' with a '_' ie: success.message -> success_message
Resource files do not allow the '.' in the key name.
Next we need to the message into the resource file.
"{0} successfully submitted the file."
We use {0}....{x} as place holders for variables.
The first line in the resource tab should look like this
The function to do the replacing of the place holders should look like this:
Now in your code all you have to do is call this function passing the resource, and the string array of variables.
That should do the trick.
I used this as a resource to compile this information.