我们新建一个提示信息,打开其中一个配置文件:
切换到resource bundle模式下,我们就可以同时编辑多个语言的提示信息,非常的方便。
3.新建国家化处理工具类
package com.ymy.utils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.context.support.ResourceBundleMessageSource;
import java.util.Locale;
@Slf4j
public class I18nUtil {
/**
-
通过code 返回对应的提示信息
-
@param code
-
@return
*/
public static String getMessage(String code) {
return getMessage(code, null);
}
/**
-
返回带参数的提示信息
-
@param code
-
@param args
-
@return
*/
public static String getMessage(String code, Object[] args) {
return getMessage(code, args, “”);
}
/**
-
根据语种查询信息
-
@param code code
-
@param args 参数
-
@param defaultMessage 默认的提示消息