All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hb0730.commons.spring.SpringMessageUtils Maven / Gradle / Ivy

There is a newer version: 2.1.2-RELEASE
Show newest version
package com.hb0730.commons.spring;

import org.springframework.context.MessageSource;
import org.springframework.context.i18n.LocaleContextHolder;

/**
 * spring message i18n
 *
 * @author bing_huang
 * @date 2020/07/30 11:56
 * @since V1.0
 */
public class SpringMessageUtils {
    /**
     * 根据消息键和参数 获取消息 委托给spring messageSource
     *
     * @param code 消息键
     * @param args 参数
     * @return 获取国际化翻译值
     */
    public static String message(String code, Object... args) {
        MessageSource messageSource = SpringContextUtil.getBean(MessageSource.class);
        return messageSource.getMessage(code, args, LocaleContextHolder.getLocale());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy