You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
763 B
Java
27 lines
763 B
Java
package com.glxp.api.util;
|
|
|
|
import lombok.AccessLevel;
|
|
import lombok.NoArgsConstructor;
|
|
import org.springframework.context.MessageSource;
|
|
import org.springframework.context.i18n.LocaleContextHolder;
|
|
|
|
/**
|
|
* 获取i18n资源文件
|
|
*/
|
|
@NoArgsConstructor(access = AccessLevel.PRIVATE)
|
|
public class MessageUtils {
|
|
|
|
private static final MessageSource MESSAGE_SOURCE = SpringUtils.getBean(MessageSource.class);
|
|
|
|
/**
|
|
* 根据消息键和参数 获取消息 委托给spring messageSource
|
|
*
|
|
* @param code 消息键
|
|
* @param args 参数
|
|
* @return 获取国际化翻译值
|
|
*/
|
|
public static String message(String code, Object... args) {
|
|
return MESSAGE_SOURCE.getMessage(code, args, LocaleContextHolder.getLocale());
|
|
}
|
|
}
|