3.7
fxl
2023-03-07 52cffc4ab8e9787a6f233295502c7c9788dddae1
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
34
35
36
37
38
39
40
41
42
43
44
45
package com.hxzkoa.util;
 
import org.springframework.context.MessageSource;
 
import java.util.Locale;
 
/**
 * 工具类
 * @author robin
 *
 */
public class ResourceUtils {
    public static MessageSource messageSource = null;
 
    public static MessageSource getMessageSource() {
        if (messageSource != null) {
            return messageSource;
        }
        try {
            return SpringContextHolder.getBean("messageSource");
        } catch (Exception e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }
        return null;
    }
 
    public static String getString(String key, Object... objects) {
        messageSource = getMessageSource();
        if (messageSource == null || key == null) {
            return "";
        }
        String result = messageSource.getMessage(key, objects, Locale.getDefault());
        if (key.equals(result)) {
            return "";
        }
        return result;
    }
 
 
    public static String getString(String key) {
        return getString(key, "");
    }
 
 
}