Mybatis-Plus 全局Update更新策略,和insert插入查询策略

从官方文档可知,数据库全局配置策略有三种,分别是查询策略,更新策略,和添加策略

从源码看

/*
 * Copyright (c) 2011-2021, baomidou (jobob@qq).
 *
 * 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
 *
 *     http://www.apache/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.annotation;

/**
 * 字段策略枚举类
 * <p>
 * 如果字段是基本数据类型则最终效果等同于 {@link #IGNORED}
 *
 * @author hubin
 * @since 2016-09-09
 */
public enum FieldStrategy {
    /**
     * 忽略判断
     */
    IGNORED,
    /**
     * 非NULL判断
     */
    NOT_NULL,
    /**
     * 非空判断(只对字符串类型字段,其他类型字段依然为非NULL判断)
     */
    NOT_EMPTY,
    /**
     * 默认的,一般只用于注解里
     * <p>1. 在全局里代表 NOT_NULL</p>
     * <p>2. 在注解里代表 跟随全局</p>
     */
    DEFAULT,
    /**
     * 不加入 SQL
     */
    NEVER
}

IGNORED 忽略判断,所有字段都进行更新和插入
NOT_NULL只更新和插入非NULL值
NOT_EMPTY 只更新和插入非NULL值且非空字符串
NEVER 永远不进行更新和插入
DEFAULT 默认NOT_NULL


/**
       * 字段验证策略之 insert: 当insert操作时,该字段拼接insert语句时的策略
       * IGNORED: 直接拼接 insert into table_a(column) values (#{columnProperty});
       * NOT_NULL: insert into table_a(<if test="columnProperty != null">column</if>) values (<if test="columnProperty != null">#{columnProperty}</if>)
       * NOT_EMPTY: insert into table_a(<if test="columnProperty != null and columnProperty!=''">column</if>) values (<if test="columnProperty != null and columnProperty!=''">#{columnProperty}</if>)
       *
       * @since 3.1.2
       */
      FieldStrategy insertStrategy() default FieldStrategy.DEFAULT;
  

      /**
       * 字段验证策略之 update: 当更新操作时,该字段拼接set语句时的策略
       * IGNORED: 直接拼接 update table_a set column=#{columnProperty}, 属性为null/空string都会被set进去
       * NOT_NULL: update table_a set <if test="columnProperty != null">column=#{columnProperty}</if>
       * NOT_EMPTY: update table_a set <if test="columnProperty != null and columnProperty!=''">column=#{columnProperty}</if>
       *
       * @since 3.1.2
       */
      FieldStrategy updateStrategy() default FieldStrategy.DEFAULT;
  

      /**
       * 字段验证策略之 where: 表示该字段在拼接where条件时的策略
       * IGNORED: 直接拼接 column=#{columnProperty}
       * NOT_NULL: <if test="columnProperty != null">column=#{columnProperty}</if>
       * NOT_EMPTY: <if test="columnProperty != null and columnProperty!=''">column=#{columnProperty}</if>
       *
       * @since 3.1.2
       */
      FieldStrategy whereStrategy() default FieldStrategy.DEFAULT;

更多推荐

mybatis-plus insertStrategy、updateStrategy、whereStrategy属性