我有一個webservice實現,它驗證請求並在響應中寫入錯誤消息。迴應不符合要求的格式。用逗號格式化Java資源包
錯誤消息模板位於資源束屬性文件中。
...
key=Plant name {0} Plant Id {1}.
...
這是錯誤信息驗證後,我得到的。
Plant name PLANT1 Plant Id 9,905,005.
但期望的輸出是與出逗號的數值變量。
Plant name WPLANT Plant Id 9905005.
這裏是我的代碼。
private String getErrorMessage(String messageKey, Object... args) {
ResourceBundle messages = ResourceBundle.getBundle("ErrorMessageResourceBundle");
MessageFormat formatter = new MessageFormat("");
formatter.applyPattern(messages.getString(messageKey));
String output = formatter.format(args);
return output;
}
我正在用下面的鍵和變量調用這個方法。
...
getErrorMessage(key,"PLANT1",9905005)
...
如何更改此代碼以獲得所需的輸出?我更喜歡一個方法不包含%s,%d,因爲此後我無法更改屬性文件中錯誤消息中變量的順序。
感謝您的回答。但它仍然用**逗號打印輸出**。 – ravindrab 2013-05-07 16:36:39