kaiyu
2020-11-30 25fae4a8608a91c5aae1db876a13cffd6418f573
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
package com.moral.common.util;
 
import java.util.Locale;
 
import org.springframework.context.MessageSource;
 
import com.moral.common.exception.ValidateException;
 
public class ValidateUtil {
    private static MessageSource resources;
 
    public static void setResources(MessageSource resources) {
        ValidateUtil.resources = resources;
    }
 
    public static void check(boolean condition, String msgKey, Object... args) {
        if (!condition) {
            fail(msgKey, args);
        }
    }
 
    public static void notEmpty(String str, String msgKey, Object... args) {
        if (str == null || str.trim().isEmpty()) {
            fail(msgKey, args);
        }
    }
 
    public static void notNull(Object obj, String msgKey, Object... args) {
        if (obj == null) {
            fail(msgKey, args);
        }
    }
 
    private static void fail(String msgKey, Object... args) {
        throw new ValidateException(resources.getMessage(msgKey, args, Locale.CHINESE));
    }
}