1

したがって、これは単に、SpringとJavaでさまざまなメッセージ解決/補間がどのように行われるかについての私自身の理解の欠如によるものであると確信しています。

InternationalMessages.properties

BadParsingFormat={{0}} should fall betweeen {1} and {2}
pointTop=The top coordinate
pointLeft=The left coordinate

APIEndPoint.java

// Standard implementation and wiring of message source
@Autowired
MessageSource messageSource;

public void someMethod(String somethingToParse) {
    String parsed;
        try {
            parsed = SomeKindOfParser.parse(somethingToParse);
        }
        catch(BadParsingFormatException exception) {
            String error = messageSource.getMessage("BadParsingFormat",
                new Object[]{
                        exception.getVariableName(),
                        exception.getLowerBound(),
                        exception.getUpperBound()
                });
            // Do something useful with this error message
        }
}

は、またはこの安っぽい例のexception.getVariableName()いずれかを返します。それらをさらに特定の名前に分解/補間したいのですが、それをうまくやってのけることができないようです。別のmessageSource呼び出しを使用して、そのバンドル値を個別に取得できることはわかっていますが、それを回避できるのであれば、それをお勧めします。pointToppointLeft

4

1 に答える 1

1

あなたがすでに提案した以外の方法を考えることはできません-messageSourceに別の呼び出しを行うために:

BadParsingFormat={0} should fall betweeen {1} and {2}
pointTop=The top coordinate
pointLeft=The left coordinate

コード付き

   String error = messageSource.getMessage("BadParsingFormat",
            new Object[]{
                    messageSource.getMessage(exception.getVariableName(),null, null),
                    exception.getLowerBound(),
                    exception.getUpperBound()
            });
于 2012-09-18T02:23:38.073 に答える