mybatis-plus insertStrategy、updateStrategy、whereStrategy属性

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

从官方文档可知,数据库全局配置策略有三种,分别是查询策略,更新策略,和添加策略
在这里插入图片描述

从源码看

/*
 * Copyright (c) 2011-2021, baomidou (jobob@qq.com).
 *
 * 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.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.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;
  • 5
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值