MessageUtils.java 739 B

1234567891011121314151617181920212223242526
  1. package com.ruoyi.common.utils;
  2. import org.springframework.context.MessageSource;
  3. import org.springframework.context.i18n.LocaleContextHolder;
  4. import com.ruoyi.common.utils.spring.SpringUtils;
  5. /**
  6. * 获取i18n资源文件
  7. *
  8. * @author ruoyi
  9. */
  10. public class MessageUtils
  11. {
  12. /**
  13. * 根据消息键和参数 获取消息 委托给spring messageSource
  14. *
  15. * @param code 消息键
  16. * @param args 参数
  17. * @return 获取国际化翻译值
  18. */
  19. public static String message(String code, Object... args)
  20. {
  21. MessageSource messageSource = SpringUtils.getBean(MessageSource.class);
  22. return messageSource.getMessage(code, args, LocaleContextHolder.getLocale());
  23. }
  24. }