Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring MVC相当于Struts for I18N的getText()_Java_Spring Mvc_Struts2_Internationalization - Fatal编程技术网

Java Spring MVC相当于Struts for I18N的getText()

Java Spring MVC相当于Struts for I18N的getText(),java,spring-mvc,struts2,internationalization,Java,Spring Mvc,Struts2,Internationalization,在Struts2ActionSupport中,类具有从i18n资源包返回本地化消息的getText(字符串键,…)方法。有没有类似的SpringMVC 我知道有标签,但这不是我需要的。我需要检索控制器类内部的本地化消息,而不是JSP上的本地化消息。您可以使用SpringMessage源代码: public class Example { private MessageSource messages; public void setMessages(MessageSource

在Struts2
ActionSupport
中,类具有从i18n资源包返回本地化消息的
getText(字符串键,…)
方法。有没有类似的SpringMVC


我知道有
标签,但这不是我需要的。我需要检索控制器类内部的本地化消息,而不是JSP上的本地化消息。

您可以使用
SpringMessage
源代码:

public class Example {

    private MessageSource messages;

    public void setMessages(MessageSource messages) {
        this.messages = messages;
    }

    public void execute() {
        String message = this.messages.getMessage("argument.required",
            new Object [] {"userDao"}, "Required", null);
        System.out.println(message);
    }

}
有关更多信息,请参见此处: