optimize codegen module

This commit is contained in:
开源海哥 2023-04-04 16:16:29 +08:00
parent e7b6792342
commit 4a35667cb2
3 changed files with 31 additions and 9 deletions

View File

@ -16,6 +16,7 @@
package com.mybatisflex.codegen.config; package com.mybatisflex.codegen.config;
import com.mybatisflex.annotation.InsertListener; import com.mybatisflex.annotation.InsertListener;
import com.mybatisflex.annotation.SetListener;
import com.mybatisflex.annotation.UpdateListener; import com.mybatisflex.annotation.UpdateListener;
import java.util.HashMap; import java.util.HashMap;
@ -42,6 +43,9 @@ public class TableConfig {
private Class<? extends UpdateListener> updateListenerClass; private Class<? extends UpdateListener> updateListenerClass;
private Class<? extends SetListener> setListenerClass;
private Map<String, ColumnConfig> columnConfigMap; private Map<String, ColumnConfig> columnConfigMap;
@ -85,6 +89,14 @@ public class TableConfig {
this.updateListenerClass = updateListenerClass; 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() { public Map<String, ColumnConfig> getColumnConfigMap() {
return columnConfigMap; return columnConfigMap;
} }

View File

@ -135,8 +135,12 @@ public class Column {
annotations.append("before=" + columnConfig.getKeyBefore()); annotations.append("before=" + columnConfig.getKeyBefore());
} }
if (annotations.length() == 4) {
annotations.deleteCharAt(annotations.length() - 1);
} else {
annotations.append(")"); annotations.append(")");
} }
}
//@Column 注解 //@Column 注解
if (columnConfig.getOnInsertValue() != null if (columnConfig.getOnInsertValue() != null

View File

@ -136,6 +136,9 @@ public class Table {
if (tableConfig.getUpdateListenerClass() != null) { if (tableConfig.getUpdateListenerClass() != null) {
imports.add(tableConfig.getUpdateListenerClass().getName()); imports.add(tableConfig.getUpdateListenerClass().getName());
} }
if (tableConfig.getSetListenerClass() != null) {
imports.add(tableConfig.getSetListenerClass().getName());
}
} }
return imports.stream().sorted(Comparator.naturalOrder()).collect(Collectors.toList()); return imports.stream().sorted(Comparator.naturalOrder()).collect(Collectors.toList());
@ -194,6 +197,9 @@ public class Table {
if (tableConfig.getUpdateListenerClass() != null) { if (tableConfig.getUpdateListenerClass() != null) {
tableAnnotation.append(", onUpdate = " + tableConfig.getUpdateListenerClass().getSimpleName() + ".class"); tableAnnotation.append(", onUpdate = " + tableConfig.getUpdateListenerClass().getSimpleName() + ".class");
} }
if (tableConfig.getSetListenerClass() != null) {
tableAnnotation.append(", onSet = " + tableConfig.getUpdateListenerClass().getSimpleName() + ".class");
}
} }
return tableAnnotation.append(")").toString(); return tableAnnotation.append(")").toString();
} }