mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 01:28:24 +08:00
fix: 主键定义在父实体类,导致代码生成器报错,关闭:https://gitee.com/mybatis-flex/mybatis-flex/issues/IA92JK,https://gitee.com/mybatis-flex/mybatis-flex/issues/IB4LOU
This commit is contained in:
parent
be8ca9a572
commit
e234a818f8
@ -107,12 +107,16 @@ public class Table {
|
||||
this.comment = comment;
|
||||
}
|
||||
|
||||
/**
|
||||
* 默认主键。
|
||||
*/
|
||||
private Column defaultPrimaryKey;
|
||||
|
||||
public Column getPrimaryKey() {
|
||||
// 这里默认表中一定会有字段,就不做空判断了
|
||||
return columns.stream()
|
||||
.filter(Column::isPrimaryKey)
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new NullPointerException("PrimaryKey can't be null"));
|
||||
if (defaultPrimaryKey == null) {
|
||||
throw new NullPointerException("PrimaryKey can't be null");
|
||||
}
|
||||
return defaultPrimaryKey;
|
||||
}
|
||||
|
||||
public Set<String> getPrimaryKeys() {
|
||||
@ -176,6 +180,7 @@ public class Table {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
List<String> superColumns = null;
|
||||
|
||||
public void addColumn(Column column) {
|
||||
@ -193,15 +198,20 @@ public class Table {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (superColumns.contains(column.getProperty())){
|
||||
return;
|
||||
}
|
||||
|
||||
// 主键
|
||||
if (primaryKeys != null && primaryKeys.contains(column.getName())) {
|
||||
column.setPrimaryKey(true);
|
||||
if (column.getAutoIncrement() == null && (column.getPropertyType().equals(Integer.class.getName()) || column.getPropertyType().equals(BigInteger.class.getName()))) {
|
||||
column.setAutoIncrement(true);
|
||||
}
|
||||
if (defaultPrimaryKey == null) {
|
||||
defaultPrimaryKey = column;
|
||||
}
|
||||
}
|
||||
|
||||
if (superColumns.contains(column.getProperty())) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (column.getAutoIncrement() == null) {
|
||||
@ -386,6 +396,7 @@ public class Table {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建 kt 继承
|
||||
*/
|
||||
|
||||
@ -18,7 +18,6 @@ package com.mybatisflex.test;
|
||||
|
||||
import com.alibaba.druid.pool.DruidDataSource;
|
||||
import com.mybatisflex.core.MybatisFlexBootstrap;
|
||||
import com.mybatisflex.core.datasource.DataSourceDecipher;
|
||||
import com.mybatisflex.core.datasource.DataSourceManager;
|
||||
import com.mybatisflex.core.datasource.DataSourceProperty;
|
||||
import com.mybatisflex.core.row.Db;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user