kimichen13 / mybatis-generator-plugin

Mybatis Gradle Generator Plugin
Apache License 2.0
102 stars 22 forks source link

custom JavaTypeResolver #1

Closed pink-lucifer closed 6 years ago

pink-lucifer commented 7 years ago

Greetings,

Hope this could add more detailed sample configuration for custom JavaTypeResolver;

In one of my project, spent bit of time while instroducing with Java 8 datetime api to figure out how to ... As follows:

  1. create custom JavaTypeResolver(in jar com.xxx.xxx:mybatis-java8:0.0.1-SNAPSHOT) public class JDK8JavaTypeResolver extends JavaTypeResolverDefaultImpl { public JDK8JavaTypeResolver() { this.typeMap.replace(Integer.valueOf(91), new JdbcTypeInformation("DATE", new FullyQualifiedJavaType(LocalDate.class.getName()))); this.typeMap.replace(Integer.valueOf(92), new JdbcTypeInformation("DATE", new FullyQualifiedJavaType(LocalTime.class.getName()))); this.typeMap.replace(Integer.valueOf(93), new JdbcTypeInformation("DATE", new FullyQualifiedJavaType(LocalDateTime.class.getName()))); } }

  2. Adding dependencies in gradle build file mybatisGenerator section mybatisGenerator { verbose = true configFile = 'src/main/resources/autogen/generatorConfig.xml' dependencies { mybatisGenerator "com.xxx.xxx:mybatis-java8:0.0.1-SNAPSHOT" mybatisGenerator 'org.mybatis.generator:mybatis-generator-core:1.3.5' mybatisGenerator 'mysql:mysql-connector-java:5.1.41' mybatisGenerator 'tk.mybatis:mapper:3.4.0' } }

  3. Adding javaTypeResolver config in configure.xml

  4. Especially, in build.gradle dependencies section: add mybatis-typehandlers-jsr310 compile group: 'org.mybatis', name: 'mybatis-typehandlers-jsr310', version: '1.0.2' see more detail: https://github.com/mybatis/typehandlers-jsr310

At your convinience, please help review ....

Hope this helps...

Cheers,

hiabp commented 6 years ago

how to add pager or limit or offset sub condition? May be can add it

pink-lucifer commented 6 years ago

@hiabp I am not sure if i follow u, please provide more detail it not too much. Furthermore, please have a look if Mybatis-PageHelper is what you are looking for?

kimichen13 commented 6 years ago

@hiabp This plugin is only for the integration of gradle and mybatis plugin. Usage of mybatis you can look on mytatis generator website.

pink-lucifer commented 6 years ago

@kimichen13

An update: start from generator 1.3.7 - a new useJSR310Types property has been introduced, set it to true will enable java8 time types. in config file:

        <javaTypeResolver>
            <property name="useJSR310Types" value="true"/>
        </javaTypeResolver>

configuration reference - javaTypeResolver

Closing it, thanks a lot,