我正在将应用程序从 struts 1 转换为 Spring MVC,并且我试图弄清楚当使用 import org.apache.struts.config.MessageResourcesConfig 和 org.apache.struts.util 时在我的 Java 代码中要做什么.消息资源。在 spring-servlet.xml 文件中,我添加了一行以包含我的消息资源属性文件,但我不再使用 struts 1 库。我将如何进行这部分代码的转换?
它在整个应用程序中被大量使用,例如这样的地方:
this.config = new MessageResourcesConfig();
this.config.setParameter("path that was used here was set in the spring-servlet configuration file");
this.resources = MessageResources.getMessageResources(this.config.getParameter());
最佳答案
我将使用java.util.ResourceBundle
重构您加载资源的方式
// load resourcebundle.properties
bundle = ResourceBundle.getBundle("resourcebundle");
然后您可以使用
获取值String val = bundle.getString(key);
您可以使用辅助类来获取所需的值,和/或找到一种将其传递给 JSP 的方法(抱歉,无法帮助您)
关于java - struts到spring迁移消息资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59140521/