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)); } }