1234567891011121314151617181920212223242526272829303132333435363738394041 |
- package cn.com.goldenwater.utils;
- import cn.com.goldenwater.exception.CheckException;
- import org.springframework.context.MessageSource;
- import java.util.Arrays;
- /**
- * @author HAIHUA2
- */
- public class CheckUtils {
- private static MessageSource resources;
- public static void setResources(MessageSource resources) {
- CheckUtils.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.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 CheckException(msgKey + ": " + Arrays.toString(args));
- // throw new CheckException(resources.getMessage(msgKey, args, Locale.CHINA));
- }
- }
|