Ver código fonte

新增管理常量的接口 Constants

miemie 7 anos atrás
pai
commit
f952ca2afe

+ 6 - 6
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/handlers/MetaObjectHandler.java

@@ -18,6 +18,8 @@ package com.baomidou.mybatisplus.core.handlers;
 import org.apache.ibatis.reflection.MetaObject;
 import org.apache.ibatis.reflection.SystemMetaObject;
 
+import com.baomidou.mybatisplus.core.toolkit.Constants;
+
 /**
  * <p>
  * 元对象字段填充控制器抽象类,实现公共字段自动写入
@@ -28,8 +30,6 @@ import org.apache.ibatis.reflection.SystemMetaObject;
  */
 public interface MetaObjectHandler {
 
-    String META_OBJ_PREFIX = "et";
-
     /**
      * <p>
      * 插入元对象字段填充
@@ -65,8 +65,8 @@ public interface MetaObjectHandler {
     default MetaObjectHandler setFieldValByName(String fieldName, Object fieldVal, MetaObject metaObject) {
         if (metaObject.hasSetter(fieldName) && metaObject.hasGetter(fieldName)) {
             metaObject.setValue(fieldName, fieldVal);
-        } else if (metaObject.hasGetter(META_OBJ_PREFIX)) {
-            Object et = metaObject.getValue(META_OBJ_PREFIX);
+        } else if (metaObject.hasGetter(Constants.META_OBJ_PREFIX)) {
+            Object et = metaObject.getValue(Constants.META_OBJ_PREFIX);
             if (et != null) {
                 MetaObject etMeta = SystemMetaObject.forObject(et);
                 if (etMeta.hasSetter(fieldName)) {
@@ -92,8 +92,8 @@ public interface MetaObjectHandler {
     default Object getFieldValByName(String fieldName, MetaObject metaObject) {
         if (metaObject.hasGetter(fieldName)) {
             return metaObject.getValue(fieldName);
-        } else if (metaObject.hasGetter(META_OBJ_PREFIX + "." + fieldName)) {
-            return metaObject.getValue(META_OBJ_PREFIX + "." + fieldName);
+        } else if (metaObject.hasGetter(Constants.META_OBJ_PREFIX + "." + fieldName)) {
+            return metaObject.getValue(Constants.META_OBJ_PREFIX + "." + fieldName);
         }
         return null;
     }

+ 3 - 3
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/mapper/BaseMapper.java

@@ -23,8 +23,8 @@ import java.util.Map;
 import org.apache.ibatis.annotations.Param;
 
 import com.baomidou.mybatisplus.core.conditions.Wrapper;
-import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.Constants;
 
 /*
 
@@ -139,7 +139,7 @@ public interface BaseMapper<T> {
      *
      * @param entity 实体对象
      */
-    Integer updateById(@Param(MetaObjectHandler.META_OBJ_PREFIX) T entity);
+    Integer updateById(@Param(Constants.META_OBJ_PREFIX) T entity);
 
     /**
      * <p>
@@ -149,7 +149,7 @@ public interface BaseMapper<T> {
      * @param entity        实体对象 (set 条件值,不能为 null)
      * @param updateWrapper 实体对象封装操作类(可以为 null,里面的 entity 用于生成 where 语句)
      */
-    Integer update(@Param(MetaObjectHandler.META_OBJ_PREFIX) T entity, @Param("ew") Wrapper<T> updateWrapper);
+    Integer update(@Param(Constants.META_OBJ_PREFIX) T entity, @Param("ew") Wrapper<T> updateWrapper);
 
     /**
      * <p>

+ 34 - 0
mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/toolkit/Constants.java

@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * 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.core.toolkit;
+
+/**
+ * <p>
+ * mybatis_plus 自用常量集中管理
+ * </p>
+ *
+ * @author miemie
+ * @since 2018-07-22
+ */
+public interface Constants {
+
+    /**
+     * 实体类前缀
+     */
+    String META_OBJ_PREFIX = "et";
+
+}