0

让我解释一下我想做什么:

我有一个包含如下属性的属性:

message=Hello {0}, welcome.

我想使用 String 在 Java 类中访问此属性并在该类中设置参数。

我已经使用 fmt:message 和 fmt:param 在 JSP 中显示这种属性,但我现在想在 Java 对象中操作它(我已经知道如何将属性注入到类中)。

关于如何做到这一点的任何想法?

4

1 回答 1

1

你可以使用java.util.ResourceBundlejava.text.MessageFormat 一些例子

private String getString( String bundle, String key, String defaultValue, Object... arguments ){
    String result = ResourceBundle.getBundle( bundle ).getString( key );
    if ( result == null ){
        result = defaultValue;
    }
    if ( arguments.length > 0 && result != null ){
        result = MessageFormat.format( result, arguments );
    }
    return result; 
}
于 2012-03-08T10:22:49.703 回答