MessageUtil.java 610 B

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