mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
optimize codegen module
This commit is contained in:
parent
e7b6792342
commit
4a35667cb2
@ -16,6 +16,7 @@
|
||||
package com.mybatisflex.codegen.config;
|
||||
|
||||
import com.mybatisflex.annotation.InsertListener;
|
||||
import com.mybatisflex.annotation.SetListener;
|
||||
import com.mybatisflex.annotation.UpdateListener;
|
||||
|
||||
import java.util.HashMap;
|
||||
@ -42,7 +43,10 @@ public class TableConfig {
|
||||
private Class<? extends UpdateListener> updateListenerClass;
|
||||
|
||||
|
||||
private Map<String,ColumnConfig> columnConfigMap;
|
||||
private Class<? extends SetListener> setListenerClass;
|
||||
|
||||
|
||||
private Map<String, ColumnConfig> columnConfigMap;
|
||||
|
||||
|
||||
public String getTableName() {
|
||||
@ -85,6 +89,14 @@ public class TableConfig {
|
||||
this.updateListenerClass = updateListenerClass;
|
||||
}
|
||||
|
||||
public Class<? extends SetListener> getSetListenerClass() {
|
||||
return setListenerClass;
|
||||
}
|
||||
|
||||
public void setSetListenerClass(Class<? extends SetListener> setListenerClass) {
|
||||
this.setListenerClass = setListenerClass;
|
||||
}
|
||||
|
||||
public Map<String, ColumnConfig> getColumnConfigMap() {
|
||||
return columnConfigMap;
|
||||
}
|
||||
@ -93,15 +105,15 @@ public class TableConfig {
|
||||
this.columnConfigMap = columnConfigMap;
|
||||
}
|
||||
|
||||
public void addColumnConfig(ColumnConfig columnConfig){
|
||||
if (columnConfigMap == null){
|
||||
public void addColumnConfig(ColumnConfig columnConfig) {
|
||||
if (columnConfigMap == null) {
|
||||
columnConfigMap = new HashMap<>();
|
||||
}
|
||||
columnConfigMap.put(columnConfig.getColumnName(), columnConfig);
|
||||
}
|
||||
|
||||
public ColumnConfig getColumnConfig(String columnName){
|
||||
return columnConfigMap == null ? null: columnConfigMap.get(columnName);
|
||||
public ColumnConfig getColumnConfig(String columnName) {
|
||||
return columnConfigMap == null ? null : columnConfigMap.get(columnName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -135,7 +135,11 @@ public class Column {
|
||||
annotations.append("before=" + columnConfig.getKeyBefore());
|
||||
}
|
||||
|
||||
annotations.append(")");
|
||||
if (annotations.length() == 4) {
|
||||
annotations.deleteCharAt(annotations.length() - 1);
|
||||
} else {
|
||||
annotations.append(")");
|
||||
}
|
||||
}
|
||||
|
||||
//@Column 注解
|
||||
|
||||
@ -78,14 +78,14 @@ public class Table {
|
||||
//主键
|
||||
if (primaryKeys != null && primaryKeys.contains(column.getName())) {
|
||||
column.setPrimaryKey(true);
|
||||
if (column.getAutoIncrement() == null){
|
||||
if (column.getPropertyType().equals(Integer.class.getName()) || column.getPropertyType().equals(BigInteger.class.getName())){
|
||||
if (column.getAutoIncrement() == null) {
|
||||
if (column.getPropertyType().equals(Integer.class.getName()) || column.getPropertyType().equals(BigInteger.class.getName())) {
|
||||
column.setAutoIncrement(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (column.getAutoIncrement() == null){
|
||||
if (column.getAutoIncrement() == null) {
|
||||
column.setAutoIncrement(false);
|
||||
}
|
||||
|
||||
@ -136,6 +136,9 @@ public class Table {
|
||||
if (tableConfig.getUpdateListenerClass() != null) {
|
||||
imports.add(tableConfig.getUpdateListenerClass().getName());
|
||||
}
|
||||
if (tableConfig.getSetListenerClass() != null) {
|
||||
imports.add(tableConfig.getSetListenerClass().getName());
|
||||
}
|
||||
}
|
||||
|
||||
return imports.stream().sorted(Comparator.naturalOrder()).collect(Collectors.toList());
|
||||
@ -194,6 +197,9 @@ public class Table {
|
||||
if (tableConfig.getUpdateListenerClass() != null) {
|
||||
tableAnnotation.append(", onUpdate = " + tableConfig.getUpdateListenerClass().getSimpleName() + ".class");
|
||||
}
|
||||
if (tableConfig.getSetListenerClass() != null) {
|
||||
tableAnnotation.append(", onSet = " + tableConfig.getUpdateListenerClass().getSimpleName() + ".class");
|
||||
}
|
||||
}
|
||||
return tableAnnotation.append(")").toString();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user