【问题标题】:JOOQ add prefix to pojo class nameJOOQ 为 pojo 类名添加前缀
【发布时间】:2022-10-18 15:16:03
【问题描述】:

我正在使用 jooq codegen 生成 pojo 类,我正在尝试使用前缀创建它们,但我不明白该怎么做。我正在使用此配置来生成它们

Configuration configuration = new Configuration()
    .withJdbc(
        new Jdbc()
            .withDriver("org.mariadb.jdbc.Driver")
            .withUrl("jdbc:mariadb://**:3306/**")
            .withUser("**")
            .withPassword("**")
    )
    .withGenerator(
        new Generator()
            .withGenerate(
                new Generate()
                    .withPojos(true)
                    .withPojosEqualsAndHashCode(true)
                    .withPojosToString(true)
                    .withDaos(true)
            )
            .withDatabase(
                new Database()
                    .withName("org.jooq.meta.mariadb.MariaDBDatabase")
                    .withIncludes(".*")
                    .withExcludes("")
                    .withInputSchema("name-db")
            )
            .withTarget(
                new Target()
                    .withPackageName("model.pack")
                    .withDirectory("model/")
            )
        );

GenerationTool.generate(configuration);

据我了解,我必须创建一个扩展“DefaultGeneratorStrategy”的类,并覆盖“getJavaClassName”方法

【问题讨论】:

  • “据我了解,我必须创建一个扩展“DefaultGeneratorStrategy”的类,并覆盖“getJavaClassName”方法”- 是的,这是一种方法。想自己回答吗?

标签: java jooq jooq-codegen


【解决方案1】:

从您对最后一部分的表述方式来看:

据我了解,我必须创建一个扩展“DefaultGeneratorStrategy”的类,并覆盖“getJavaClassName”方法

我认为您已经找到了如何做到这一点,即使用generator strategy,并且想联系其他人为您实施它,具体来说?

相反,让我提供一种比上述编程策略更简单的方法,使用配置策略,如果这真的只是一个类名前缀。使用matcher strategies

new Configuration()
  .withGenerator(new Generator()
    .withStrategy(new Strategy()
      .withMatchers(new Matchers()
        .withTables(
          new MatchersTableType()
            .withExpression("MY_TABLE")
            .withPojoClass(new MatcherRule()
              .withTransform(MatcherTransformType.PASCAL)
              .withExpression("PREFIX_$0")
            )
        )
      )
    )
  );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-01-30
    • 1970-01-01
    • 2011-03-04
    • 1970-01-01
    • 2013-06-22
    • 1970-01-01
    • 2018-11-10
    • 2012-06-18
    相关资源
    最近更新 更多