diff --git a/src/main/java/com/zzg/mybatis/generator/bridge/MybatisGeneratorBridge.java b/src/main/java/com/zzg/mybatis/generator/bridge/MybatisGeneratorBridge.java index f2e8de18..aabdce73 100644 --- a/src/main/java/com/zzg/mybatis/generator/bridge/MybatisGeneratorBridge.java +++ b/src/main/java/com/zzg/mybatis/generator/bridge/MybatisGeneratorBridge.java @@ -185,6 +185,12 @@ public void generate() throws Exception { context.addPluginConfiguration(pluginConfiguration); } } + //for JSR310 + if (generatorConfig.isJsr310Support()) { + JavaTypeResolverConfiguration javaTypeResolverConfiguration = new JavaTypeResolverConfiguration(); + javaTypeResolverConfiguration.setConfigurationType("com.zzg.mybatis.generator.plugins.JavaTypeResolverJsr310Impl"); + context.setJavaTypeResolverConfiguration(javaTypeResolverConfiguration); + } context.setTargetRuntime("MyBatis3"); List warnings = new ArrayList<>(); diff --git a/src/main/java/com/zzg/mybatis/generator/controller/MainUIController.java b/src/main/java/com/zzg/mybatis/generator/controller/MainUIController.java index b6c5e47b..8b3fe6ce 100644 --- a/src/main/java/com/zzg/mybatis/generator/controller/MainUIController.java +++ b/src/main/java/com/zzg/mybatis/generator/controller/MainUIController.java @@ -83,6 +83,8 @@ public class MainUIController extends BaseFXController { @FXML private CheckBox useSchemaPrefix; @FXML + private CheckBox jsr310Support; + @FXML private TreeView leftDBTree; // Current selected databaseConfig private DatabaseConfig selectedDatabaseConfig; @@ -327,6 +329,7 @@ public GeneratorConfig getGeneratorConfigFromUI() { generatorConfig.setEncoding(encodingChoice.getValue()); generatorConfig.setUseExampe(useExample.isSelected()); generatorConfig.setUseSchemaPrefix(useSchemaPrefix.isSelected()); + generatorConfig.setJsr310Support(jsr310Support.isSelected()); return generatorConfig; } diff --git a/src/main/java/com/zzg/mybatis/generator/model/GeneratorConfig.java b/src/main/java/com/zzg/mybatis/generator/model/GeneratorConfig.java index 794da88b..0b80be52 100644 --- a/src/main/java/com/zzg/mybatis/generator/model/GeneratorConfig.java +++ b/src/main/java/com/zzg/mybatis/generator/model/GeneratorConfig.java @@ -58,6 +58,16 @@ public class GeneratorConfig { private boolean useSchemaPrefix; + private boolean jsr310Support; + + public boolean isJsr310Support() { + return jsr310Support; + } + + public void setJsr310Support(boolean jsr310Support) { + this.jsr310Support = jsr310Support; + } + public boolean isUseSchemaPrefix() { return useSchemaPrefix; } diff --git a/src/main/java/com/zzg/mybatis/generator/plugins/JavaTypeResolverJsr310Impl.java b/src/main/java/com/zzg/mybatis/generator/plugins/JavaTypeResolverJsr310Impl.java new file mode 100644 index 00000000..f84f783a --- /dev/null +++ b/src/main/java/com/zzg/mybatis/generator/plugins/JavaTypeResolverJsr310Impl.java @@ -0,0 +1,45 @@ +package com.zzg.mybatis.generator.plugins; + +import org.mybatis.generator.api.IntrospectedColumn; +import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType; +import org.mybatis.generator.internal.types.JavaTypeResolverDefaultImpl; + +import java.sql.Types; +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.LocalTime; + +/** + * @author hanakei + * @since 2018/4/28 + */ +public class JavaTypeResolverJsr310Impl extends JavaTypeResolverDefaultImpl { + + @Override + protected FullyQualifiedJavaType overrideDefaultType(IntrospectedColumn column, FullyQualifiedJavaType defaultType) { + FullyQualifiedJavaType answer = defaultType; + + switch (column.getJdbcType()) { + case Types.BIT: + answer = calculateBitReplacement(column, defaultType); + break; + case Types.DECIMAL: + case Types.NUMERIC: + answer = calculateBigDecimalReplacement(column, defaultType); + break; + case Types.DATE: + answer = new FullyQualifiedJavaType(LocalDate.class.getName()); + break; + case Types.TIME: + answer = new FullyQualifiedJavaType(LocalTime.class.getName()); + break; + case Types.TIMESTAMP: + answer = new FullyQualifiedJavaType(LocalDateTime.class.getName()); + break; + default: + break; + } + + return answer; + } +} diff --git a/src/main/resources/fxml/MainUI.fxml b/src/main/resources/fxml/MainUI.fxml index 0e592252..0457fed7 100644 --- a/src/main/resources/fxml/MainUI.fxml +++ b/src/main/resources/fxml/MainUI.fxml @@ -204,6 +204,11 @@ + + + + +