springboot国际化
不需要引入额外的jar包
参考:https://zhuanlan.zhihu.com/p/551605839
1.rources要创建Resource Bundle
2.yml配置中引入Resource Bundle
引入Resource Bundle
spring:messages:encoding: UTF-8basename: i18n/messages_common
3.创建国际化工具
/*** 国际化** @author Mark sunlightcs@gmail.com* @since 1.0.0*/
public class MessageUtils {private static MessageSource messageSource;static {messageSource = (MessageSource)SpringContextUtils.getBean("messageSource");}public static String getMessage(int code){return getMessage(code, new String[0]);}public static String getMessage(int code, String... params){return messageSource.getMessage(code+"", params, LocaleContextHolder.getLocale());}
}
4.在校验中使用国际化提示信息
public ZenException(int code, String... params) {this.code = code;this.msg = MessageUtils.getMessage(code, params);
}