Skip to content

Commit

Permalink
JSR310: Date and Time API
Browse files Browse the repository at this point in the history
  • Loading branch information
hanakeichen committed Apr 28, 2018
1 parent f5bfe6c commit 44bbc4f
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> warnings = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ public class MainUIController extends BaseFXController {
@FXML
private CheckBox useSchemaPrefix;
@FXML
private CheckBox jsr310Support;
@FXML
private TreeView<String> leftDBTree;
// Current selected databaseConfig
private DatabaseConfig selectedDatabaseConfig;
Expand Down Expand Up @@ -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;
}

Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/zzg/mybatis/generator/model/GeneratorConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
5 changes: 5 additions & 0 deletions src/main/resources/fxml/MainUI.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@
<CheckBox fx:id="useExample" mnemonicParsing="false" selected="true" text="使用Example" />
</children>
</HBox>
<HBox prefHeight="100.0" prefWidth="200.0">
<children>
<CheckBox fx:id="jsr310Support" mnemonicParsing="false" text="JSR310: Date and Time API" />
</children>
</HBox>
</children>
<padding>
<Insets left="5.0" />
Expand Down

0 comments on commit 44bbc4f

Please sign in to comment.