update 禁止所有工具类实例化 优化代码书写规范

This commit is contained in:
疯狂的狮子li
2021-12-06 10:59:54 +08:00
parent 1b752c35cc
commit e11a6163dd
17 changed files with 93 additions and 42 deletions

View File

@ -1,15 +1,21 @@
package com.ruoyi.common.utils;
import com.ruoyi.common.utils.spring.SpringUtils;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;
/**
* 获取i18n资源文件
*
* @author ruoyi
* @author Lion Li
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class MessageUtils {
private static final MessageSource MESSAGE_SOURCE = SpringUtils.getBean(MessageSource.class);
/**
* 根据消息键和参数 获取消息 委托给spring messageSource
*
@ -18,7 +24,6 @@ public class MessageUtils {
* @return 获取国际化翻译值
*/
public static String message(String code, Object... args) {
MessageSource messageSource = SpringUtils.getBean(MessageSource.class);
return messageSource.getMessage(code, args, LocaleContextHolder.getLocale());
return MESSAGE_SOURCE.getMessage(code, args, LocaleContextHolder.getLocale());
}
}