Skip to content

MybatisR2dbcGenerator

GangCheng edited this page Jan 22, 2024 · 2 revisions
  • The mybatis-r2dbc-generator is aimed to generate classes used by mybatis-dynamic-sql, and make it compatible with mybatis-r2dbc.
  • Generator usage:
    • import dependencies
<dependencies>
      <dependency>
          <groupId>org.mybatis.dynamic-sql</groupId>
          <artifactId>mybatis-dynamic-sql</artifactId>
          <version>${spedific-version}</version>
      </dependency>
      <!-- test scope -->
      <!-- JDBC database driver for generator -->
      <dependency>
          <groupId>mysql</groupId>
          <artifactId>mysql-connector-java</artifactId>
          <scope>test</scope>
      </dependency>
      <dependency>
          <groupId>pro.chenggang</groupId>
          <artifactId>mybatis-r2dbc-generator</artifactId>
          <version>${compatible-version}</version>
          <scope>test</scope>
      </dependency>
</dependencies>
  • Copy mybatis-generator.yml to your src/java/test/resources directory.
  • Modify target database settings in mybatis-generator.yml, more detail please see the mybatis-generator.yml's comment inline.
  • Customize the generator runtime settings in test source root
    // generate through test method
    @Test
    public void generateWithYamlWithJunitTestMethod() {
        MybatisDynamicCodeGenerator.withYamlConfiguration()
                .customConfigure()
            // When using test method to run generator execution, the base package location would automatically determined by current test class
                .applyGenerateBasePackageFromClass(MyBatisGeneratorAction.class)
                .configureGeneratedJavaTypeModifier(TestJavaTypeModifier.class)
                .toGenerator()
                .generate();
    }
    /**
     * generate through main method
     *
     * @param args args
     */
    public static void main(String[] args) {
        String codeAbsoluteLocation = new File("").getAbsolutePath() + "/mybatis-r2dbc-generator";
        MybatisDynamicCodeGenerator.withYamlConfiguration()
                .customConfigure()
            // When using main method to run generator execution, the base package location should be configured manually
                .configureGenerateBasePackage(codeAbsoluteLocation, "pro.chenggang.project.reactive.mybatis.support.generator")
                .configureGeneratedJavaTypeModifier(TestJavaTypeModifier.class)
                .toGenerator()
                .generate();
    }
  • Demo Generator Test