Skip to content

Commit c7edec6

Browse files
committed
主键处理.
1 parent 0dd8415 commit c7edec6

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/builder/ConfigBuilder.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ private void checkImportPackages(TableInfo tableInfo) {
398398
// 无父类开启 AR 模式
399399
tableInfo.getImportPackages().add(com.baomidou.mybatisplus.extension.activerecord.Model.class.getCanonicalName());
400400
}
401-
if (null != globalConfig.getIdType() && tableInfo.hasPrimaryKey()) {
401+
if (null != globalConfig.getIdType() && tableInfo.isHavePrimaryKey()) {
402402
// 指定需要 IdType 场景
403403
tableInfo.getImportPackages().add(com.baomidou.mybatisplus.annotation.IdType.class.getCanonicalName());
404404
tableInfo.getImportPackages().add(com.baomidou.mybatisplus.annotation.TableId.class.getCanonicalName());
@@ -636,11 +636,10 @@ private TableInfo convertTableFields(TableInfo tableInfo, StrategyConfig config)
636636

637637
// 处理ID
638638
if (isId && !haveId) {
639-
field.setKeyFlag(true);
640-
if (DbType.H2 == dbType || DbType.SQLITE == dbType || dbQuery.isKeyIdentity(results)) {
641-
field.setKeyIdentityFlag(true);
642-
}
643639
haveId = true;
640+
field.setKeyFlag(true);
641+
tableInfo.setHavePrimaryKey(true);
642+
field.setKeyIdentityFlag(dbQuery.isKeyIdentity(results));
644643
} else {
645644
field.setKeyFlag(false);
646645
}

mybatis-plus-generator/src/main/java/com/baomidou/mybatisplus/generator/config/po/TableInfo.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public class TableInfo {
4949
private String serviceImplName;
5050
private String controllerName;
5151
private List<TableField> fields;
52+
private boolean havePrimaryKey;
5253
/**
5354
* 公共字段
5455
*/
@@ -158,13 +159,4 @@ public String getFieldNames() {
158159
return fieldNames;
159160
}
160161

161-
/**
162-
* 是否含有主键
163-
*
164-
* @return 是否含有主键
165-
* @since 3.3.3
166-
*/
167-
public boolean hasPrimaryKey() {
168-
return this.fields.stream().anyMatch(TableField::isKeyFlag);
169-
}
170162
}

0 commit comments

Comments
 (0)