Commit 5ff10c80 authored by Quxl's avatar Quxl

x

parent 3596836a
...@@ -5,6 +5,7 @@ import java.util.Locale; ...@@ -5,6 +5,7 @@ import java.util.Locale;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
import org.springframework.context.NoSuchMessageException;
import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
...@@ -45,6 +46,7 @@ public class I18NUtils { ...@@ -45,6 +46,7 @@ public class I18NUtils {
* @date 2018年4月11日 下午8:35:15 * @date 2018年4月11日 下午8:35:15
*/ */
public static String getMessage(String LangID,String key,Object...values){ public static String getMessage(String LangID,String key,Object...values){
try {
if(StringUtil.isEmpty(LangID)){ //为空默认为中文 if(StringUtil.isEmpty(LangID)){ //为空默认为中文
Locale.setDefault(Locale.CHINA); Locale.setDefault(Locale.CHINA);
}else{ }else{
...@@ -58,6 +60,9 @@ public class I18NUtils { ...@@ -58,6 +60,9 @@ public class I18NUtils {
System.out.println("locale---------------"+locale); System.out.println("locale---------------"+locale);
String msg = source.getMessage(key, null, locale); String msg = source.getMessage(key, null, locale);
return MessageFormat.format(msg, values); return MessageFormat.format(msg, values);
} catch (Exception e) {
return key;
}
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment