浏览代码

支持通用 api 处理方式, 修改license 时长

hubin 7 年之前
父节点
当前提交
f1cca03519
共有 26 个文件被更改,包括 549 次插入18 次删除
  1. 1 1
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/MybatisDefaultParameterHandler.java
  2. 1 1
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/MybatisSessionFactoryBuilder.java
  3. 1 1
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/MybatisXMLConfigBuilder.java
  4. 1 1
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/MybatisXMLLanguageDriver.java
  5. 1 1
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/Wrapper.java
  6. 1 1
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/select/EntityWrapper.java
  7. 1 1
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/config/GlobalConfig.java
  8. 1 1
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/enums/SqlLike.java
  9. 1 1
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/enums/SqlMethod.java
  10. 1 1
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/exceptions/MybatisPlusException.java
  11. 1 1
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/injector/SqlRunnerInjector.java
  12. 1 1
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/metadata/Column.java
  13. 1 1
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/metadata/Columns.java
  14. 1 1
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/metadata/TableInfo.java
  15. 1 1
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/pagination/Page.java
  16. 1 1
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/pagination/dialect/IDialect.java
  17. 1 1
      mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/toolkit/StringUtils.java
  18. 37 0
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/api/IErrorCode.java
  19. 180 0
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/api/RestAssert.java
  20. 114 0
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/api/RestResult.java
  21. 9 0
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/api/package-info.java
  22. 70 0
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/enums/ApiErrorCode.java
  23. 1 1
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/enums/DBType.java
  24. 55 0
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/exceptions/RestException.java
  25. 4 0
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/exceptions/package-info.java
  26. 62 0
      mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/toolkit/ObjectUtils.java

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/MybatisDefaultParameterHandler.java

@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
  * <p>
  * <p>
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
  * use this file except in compliance with the License. You may obtain a copy of

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/MybatisSessionFactoryBuilder.java

@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
  * <p>
  * <p>
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
  * use this file except in compliance with the License. You may obtain a copy of

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/MybatisXMLConfigBuilder.java

@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
  * <p>
  * <p>
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
  * use this file except in compliance with the License. You may obtain a copy of

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/MybatisXMLLanguageDriver.java

@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
  * <p>
  * <p>
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
  * use this file except in compliance with the License. You may obtain a copy of

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/Wrapper.java

@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
  * <p>
  * <p>
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
  * use this file except in compliance with the License. You may obtain a copy of

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/conditions/select/EntityWrapper.java

@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
  * <p>
  * <p>
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
  * use this file except in compliance with the License. You may obtain a copy of

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/config/GlobalConfig.java

@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
  * <p>
  * <p>
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
  * use this file except in compliance with the License. You may obtain a copy of

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/enums/SqlLike.java

@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
  * <p>
  * <p>
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
  * use this file except in compliance with the License. You may obtain a copy of

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/enums/SqlMethod.java

@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
  * <p>
  * <p>
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
  * use this file except in compliance with the License. You may obtain a copy of

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/exceptions/MybatisPlusException.java

@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
  * <p>
  * <p>
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
  * use this file except in compliance with the License. You may obtain a copy of

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/injector/SqlRunnerInjector.java

@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
  * <p>
  * <p>
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
  * use this file except in compliance with the License. You may obtain a copy of

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/metadata/Column.java

@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
  * <p>
  * <p>
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
  * use this file except in compliance with the License. You may obtain a copy of

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/metadata/Columns.java

@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
  * <p>
  * <p>
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
  * use this file except in compliance with the License. You may obtain a copy of

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/metadata/TableInfo.java

@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
  * <p>
  * <p>
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
  * use this file except in compliance with the License. You may obtain a copy of

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/pagination/Page.java

@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
  * <p>
  * <p>
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
  * use this file except in compliance with the License. You may obtain a copy of

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/pagination/dialect/IDialect.java

@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
  * <p>
  * <p>
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
  * use this file except in compliance with the License. You may obtain a copy of

+ 1 - 1
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/toolkit/StringUtils.java

@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
  * <p>
  * <p>
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
  * use this file except in compliance with the License. You may obtain a copy of

+ 37 - 0
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/api/IErrorCode.java

@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.baomidou.mybatisplus.extension.api;
+
+/**
+ * <p>
+ * 错误码接口
+ * </p>
+ *
+ * @author hubin
+ * @since 2018-06-05
+ */
+public interface IErrorCode {
+
+    /**
+     * 错误编码 0、失败 1、正常
+     */
+    String getCode();
+
+    /**
+     * 错误描述
+     */
+    String getMsg();
+}

+ 180 - 0
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/api/RestAssert.java

@@ -0,0 +1,180 @@
+/*
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.baomidou.mybatisplus.extension.api;
+
+import java.util.Collection;
+import java.util.Map;
+
+
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.baomidou.mybatisplus.core.toolkit.MapUtils;
+import com.baomidou.mybatisplus.extension.exceptions.RestException;
+import com.baomidou.mybatisplus.extension.toolkit.ObjectUtils;
+
+/**
+ * <p>
+ * REST 业务断言<br>
+ * 参考:org.junit.Assert
+ * </p>
+ *
+ * @author hubin
+ * @since 2018-06-05
+ */
+public class RestAssert {
+
+    protected RestAssert() {
+        // to do noting
+    }
+
+    /**
+     * 大于O
+     */
+    public static void gtZero(Integer num, IErrorCode errorCode) {
+        if (num == null || num <= 0) {
+            fail(errorCode);
+        }
+    }
+
+    /**
+     * 大于等于O
+     */
+    public static void geZero(Integer num, IErrorCode errorCode) {
+        if (num == null || num < 0) {
+            fail(errorCode);
+        }
+    }
+
+    /**
+     * num1大于num2
+     */
+    public static void gt(Integer num1, Integer num2, IErrorCode errorCode) {
+        if (num1 <= num2) {
+            fail(errorCode);
+        }
+    }
+
+    /**
+     * num1大于等于num2
+     */
+    public static void ge(Integer num1, Integer num2, IErrorCode errorCode) {
+        if (num1 < num2) {
+            fail(errorCode);
+        }
+    }
+
+    /**
+     * obj1 eq obj2
+     */
+    public static void eq(Object obj1, Object obj2, IErrorCode errorCode) {
+        if (!obj1.equals(obj2)) {
+            fail(errorCode);
+        }
+    }
+
+    public static void isTrue(boolean condition, IErrorCode errorCode) {
+        if (!condition) {
+            fail(errorCode);
+        }
+    }
+
+    public static void isFalse(boolean condition, IErrorCode errorCode) {
+        if (condition) {
+            fail(errorCode);
+        }
+    }
+
+    public static void isNull(IErrorCode errorCode, Object... conditions) {
+        if (ObjectUtils.isNotNull(conditions)) {
+            fail(errorCode);
+        }
+    }
+
+    public static void notNull(IErrorCode errorCode, Object... conditions) {
+        if (ObjectUtils.isNull(conditions)) {
+            fail(errorCode);
+        }
+    }
+
+    /**
+     * <p>
+     * 失败结果
+     * </p>
+     *
+     * @param errorCode 异常错误码
+     */
+    public static void fail(IErrorCode errorCode) {
+        throw new RestException(errorCode);
+    }
+
+    public static void fail(boolean condition, IErrorCode errorCode) {
+        if (condition) {
+            fail(errorCode);
+        }
+    }
+
+    public static void fail(String message) {
+        throw new RestException(message);
+    }
+
+    public static void fail(boolean condition, String message) {
+        if (condition) {
+            fail(message);
+        }
+    }
+
+    public static void notEmpty(Object[] array, IErrorCode errorCode) {
+        if (ObjectUtils.isEmpty(array)) {
+            fail(errorCode);
+        }
+    }
+
+    public static void noNullElements(Object[] array, IErrorCode errorCode) {
+        if (array != null) {
+            for (Object element : array) {
+                if (element == null) {
+                    fail(errorCode);
+                }
+            }
+        }
+    }
+
+    public static void notEmpty(Collection<?> collection, IErrorCode errorCode) {
+        if (CollectionUtils.isNotEmpty(collection)) {
+            fail(errorCode);
+        }
+    }
+
+    public static void notEmpty(Map<?, ?> map, IErrorCode errorCode) {
+        if (MapUtils.isEmpty(map)) {
+            fail(errorCode);
+        }
+    }
+
+    public static void isInstanceOf(Class<?> type, Object obj, IErrorCode errorCode) {
+        notNull(errorCode, type);
+        if (!type.isInstance(obj)) {
+            fail(errorCode);
+        }
+    }
+
+    public static void isAssignable(Class<?> superType, Class<?> subType, IErrorCode errorCode) {
+        notNull(errorCode, superType);
+        if (subType == null || !superType.isAssignableFrom(subType)) {
+            fail(errorCode);
+        }
+    }
+
+}

+ 114 - 0
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/api/RestResult.java

@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.baomidou.mybatisplus.extension.api;
+
+import com.baomidou.mybatisplus.extension.enums.ApiErrorCode;
+import com.baomidou.mybatisplus.extension.exceptions.RestException;
+
+/**
+ * <p>
+ * API REST 返回结果
+ * </p>
+ *
+ * @author hubin
+ * @since 2018-06-05
+ */
+public class RestResult<T> {
+
+    /**
+     * 业务错误码
+     */
+    private String code;
+    /**
+     * 结果集
+     */
+    private T data;
+    /**
+     * 描述
+     */
+    private String msg;
+
+    public RestResult() {
+        // to do nothing
+    }
+
+    public RestResult(IErrorCode errorCode) {
+        if (errorCode == null) {
+            errorCode = ApiErrorCode.FAILED;
+        }
+        this.code = errorCode.getCode();
+        this.msg = errorCode.getMsg();
+    }
+
+    public static <T> RestResult<T> ok(T data) {
+        return restResult(data, ApiErrorCode.SUCCESS);
+    }
+
+    public static <T> RestResult<T> failed(String msg) {
+        return restResult(null, ApiErrorCode.FAILED.getCode(), msg);
+    }
+
+    public static <T> RestResult<T> failed(IErrorCode errorCode) {
+        return restResult(null, errorCode);
+    }
+
+    public static <T> RestResult<T> restResult(T data, IErrorCode errorCode) {
+        return restResult(data, errorCode.getCode(), errorCode.getMsg());
+    }
+
+    private static <T> RestResult<T> restResult(T data, String code, String msg) {
+        RestResult<T> restResult = new RestResult<>();
+        restResult.setCode(code);
+        restResult.setData(data);
+        restResult.setMsg(msg);
+        return restResult;
+    }
+
+    public boolean isSuccess() {
+        return ApiErrorCode.SUCCESS.getCode().equals(this.code);
+    }
+
+    public T getData(IErrorCode errorCode) {
+        if (!isSuccess()) {
+            throw new RestException(errorCode);
+        }
+        return data;
+    }
+
+    public T getData() {
+        return data;
+    }
+
+    public void setData(T data) {
+        this.data = data;
+    }
+
+    public String getCode() {
+        return code;
+    }
+
+    public void setCode(String code) {
+        this.code = code;
+    }
+
+    public String getMsg() {
+        return msg;
+    }
+
+    public void setMsg(String msg) {
+        this.msg = msg;
+    }
+}

+ 9 - 0
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/api/package-info.java

@@ -0,0 +1,9 @@
+/**
+ * <p>
+ * 通用 Controller API 层封装
+ * </p>
+ *
+ * @author hubin
+ * @since 2018-06-05
+ */
+package com.baomidou.mybatisplus.extension.api;

+ 70 - 0
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/enums/ApiErrorCode.java

@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.baomidou.mybatisplus.extension.enums;
+
+import com.baomidou.mybatisplus.extension.api.IErrorCode;
+
+/**
+ * <p>
+ * 错误码
+ * </p>
+ *
+ * @author hubin
+ * @since 2017-06-26
+ */
+public enum ApiErrorCode implements IErrorCode {
+    /**
+     * 失败
+     */
+    FAILED("0", "失败"),
+    /**
+     * 成功
+     */
+    SUCCESS("1", "成功");
+
+    private final String code;
+    private final String msg;
+
+    ApiErrorCode(final String code, final String msg) {
+        this.code = code;
+        this.msg = msg;
+    }
+
+    public static ApiErrorCode fromCode(String code) {
+        ApiErrorCode[] ecs = ApiErrorCode.values();
+        for (ApiErrorCode ec : ecs) {
+            if (ec.getCode().equalsIgnoreCase(code)) {
+                return ec;
+            }
+        }
+        return SUCCESS;
+    }
+
+    @Override
+    public String getCode() {
+        return code;
+    }
+
+    @Override
+    public String getMsg() {
+        return msg;
+    }
+
+    @Override
+    public String toString() {
+        return String.format(" ErrorCode:{code=%s, msg=%s} ", code, msg);
+    }
+}

+ 1 - 1
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/enums/DBType.java

@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2011-2014, hubin (jobob@qq.com).
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
  * <p>
  * <p>
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
  * use this file except in compliance with the License. You may obtain a copy of

+ 55 - 0
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/exceptions/RestException.java

@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2011-2020, hubin (jobob@qq.com).
+ * <p>
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.baomidou.mybatisplus.extension.exceptions;
+
+import com.baomidou.mybatisplus.extension.api.IErrorCode;
+
+/**
+ * <p>
+ * Rest 请求异常类
+ * </p>
+ *
+ * @author hubin
+ * @since 2017-06-26
+ */
+public class RestException extends RuntimeException {
+
+    /**
+     * 错误码
+     */
+    private IErrorCode errorCode;
+
+    public RestException(IErrorCode errorCode) {
+        super(errorCode.getMsg());
+        this.errorCode = errorCode;
+    }
+
+    public RestException(String message) {
+        super(message);
+    }
+
+    public RestException(Throwable cause) {
+        super(cause);
+    }
+
+    public RestException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public IErrorCode getErrorCode() {
+        return errorCode;
+    }
+}

+ 4 - 0
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/exceptions/package-info.java

@@ -0,0 +1,4 @@
+/**
+ * 扩展功能异常
+ */
+package com.baomidou.mybatisplus.extension.exceptions;

+ 62 - 0
mybatis-plus-extension/src/main/java/com/baomidou/mybatisplus/extension/toolkit/ObjectUtils.java

@@ -0,0 +1,62 @@
+package com.baomidou.mybatisplus.extension.toolkit;
+
+import java.lang.reflect.Array;
+import java.util.Collection;
+import java.util.Map;
+
+/**
+ * <p>
+ * 对象工具类
+ * <p>
+ *
+ * @author hubin
+ * @since 2018-06-05
+ */
+public class ObjectUtils {
+
+
+    /**
+     * 判断object是否为空,集合会校验size
+     */
+    public static boolean isNull(Object... objs) {
+        for (Object obj : objs) {
+            if (isEmpty(obj)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+
+    /**
+     * 判断object是否不为空,集合会校验size
+     */
+    public static boolean isNotNull(Object... obj) {
+        return !isNull(obj);
+    }
+
+    /**
+     * 对象非空判断
+     */
+    public static boolean isEmpty(Object obj) {
+        if (obj == null) {
+            return true;
+        }
+
+        if (obj.getClass().isArray()) {
+            return Array.getLength(obj) == 0;
+        }
+        if (obj instanceof CharSequence) {
+            return ((CharSequence) obj).length() == 0;
+        }
+        if (obj instanceof Collection) {
+            return ((Collection) obj).isEmpty();
+        }
+        if (obj instanceof Map) {
+            return ((Map) obj).isEmpty();
+        }
+        // else
+        return false;
+    }
+
+}