先寫好幾個.properties的資源檔案放在classpath下,當然可以放在src下面
我寫了兩個:
format.properties //內容--->testmsg=hello world
exception.properties
//--->run=runtimeexception null=nullpointexception #中國 china=\u4e2d\u56fd
然後在主配置當中配置:
format
exception
這裡利用messageresource提供國際化的訊息訪問,
接下來編寫我的測試類:
測試結果:
中國當然還可以用注入的方式把messageresource 注入到類體當中,不過這樣加大了spring與應用程式的耦合度。
Spring 國際化資源
spring 國際化資源 以前,在學習struts2的時候經常聽到關於國際化的訊息。記得struts2國際化的時候我們需要在cmd下面編譯資源檔案,但是spring在資源國際化的時候則不需要這麼麻煩。而且如果你是使用 eclipse或者myeclipse的話,當你新建好message en us.p...
基於Spring 國際化
classpath valid validation classpath local message 以上是spring 國際化 所需要配置的,有了interceptors,controler 就不用設定了,類似於下面 locale locale null locale new locale zh ...
Spring MVC國際化配置
一 基於瀏覽器語言的國際化配置 使用spring的mvc,並且配置中有配置resource檔案 其中,message info是你的properties檔案的通用名。如 我的配置檔案叫message info.properties,message info zh cn.properties等等,只要...