Skip to content

Commit

Permalink
新增自增主键兼容配置开关.
Browse files Browse the repository at this point in the history
  • Loading branch information
nieqiurong committed Mar 27, 2024
1 parent be5ba34 commit bc67993
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,14 @@ public static class DbConfig {
*/
private FieldStrategy whereStrategy = FieldStrategy.NOT_NULL;

/**
* 生成INSERT语句时忽略自增主键字段(默认不忽略,主键有值时写入主键值,无值自增).
* <p>当设置为true时,执行生成SQL语句无论ID是否有值都会忽视 (此为3.4.3.1版本下策略,如果升级遇到问题可以考虑开启此配置来兼容升级)</p>
*
* @since 3.5.6
*/
private boolean insertIgnoreAutoIncrementColumn = false;

/**
* 重写whereStrategy的get方法,适配低版本:
* - 如果用户自定义了selectStrategy则用用户自定义的,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
*/
package com.baomidou.mybatisplus.core.injector;

import com.baomidou.mybatisplus.core.config.GlobalConfig;
import com.baomidou.mybatisplus.core.injector.methods.*;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.baomidou.mybatisplus.core.toolkit.GlobalConfigUtils;

import java.util.List;
import java.util.stream.Stream;
Expand All @@ -34,8 +36,9 @@ public class DefaultSqlInjector extends AbstractSqlInjector {

@Override
public List<AbstractMethod> getMethodList(Class<?> mapperClass, TableInfo tableInfo) {
GlobalConfig.DbConfig dbConfig = GlobalConfigUtils.getDbConfig(tableInfo.getConfiguration());
Stream.Builder<AbstractMethod> builder = Stream.<AbstractMethod>builder()
.add(new Insert())
.add(new Insert(dbConfig.isInsertIgnoreAutoIncrementColumn()))
.add(new Delete())
.add(new Update())
.add(new SelectCount())
Expand Down

0 comments on commit bc67993

Please sign in to comment.