gpt4 book ai didi

java - struts到spring迁移消息资源

转载 作者:行者123 更新时间:2023-12-02 09:14:08 31 4
gpt4 key购买 nike

我正在将应用程序从 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/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com