kongzy
2024-07-01 47a751cb301d05276ae5d75145d57b2d090fe4e1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package com.nanometer.smartlab.util;
 
import com.nanometer.smartlab.service.SmartLabSpringContext;
import org.springframework.context.support.ResourceBundleMessageSource;
 
/**
 * Created by johnny on 17/6/12.
 */
public class MessageUtil {
 
    private static ResourceBundleMessageSource messageSource = null;
 
    public static String getMessage(String key) {
        return getMessage(key, null);
    }
 
    public static String getMessage(String key, Object... values) {
        if (messageSource == null) {
            messageSource = (ResourceBundleMessageSource) SmartLabSpringContext.getBean("messageSource");
        }
        String s = messageSource.getMessage(key, values, null);
        return s;
    }
 
    public static String getMessageByCode(String code , Object... values) {
        String key = "code_" + code;
        return getMessage(key, values);
    }
 
    public static String getMessageByCode(String code) {
        return getMessageByCode(code, null);
    }
}