0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

MyBatis Generator の各種設定の覚書き

Posted at

はじめに

MyBatis Generatorを使用するにあたり、各種設定に関して気になったことをまとめました。

lombok対応

lombok対応のMyBatis Generatorプラグインがあるので、それを使用します。

generatorConfig.xmlファイルにプラグインを追加します。

generatorConfig.xml
...
    <context ...>
        <!-- lombok対応 -->
        <plugin type="com.softwareloop.mybatis.generator.plugins.LombokPlugin">
        </plugin>
...

上記設定で、モデルクラスに@Dateアノテーションが付与されます。
その他、当プラグインには、いろいろな設定項目があります。

generatorConfig.xmlに上記を設定後、実行するための設定は、EclipseプラグインとMavenでは違うので、それぞれ以下に示します。

Eclipseプラグインを利用する場合

pom.xmlの<dependencies>タグに以下を追加し、lombok対応用プラグインをプロジェクトのビルドパスに追加します。

pom.xml
...
    <dependencies>
        <!-- MyBatis Generator用lombok対応プラグイン -->
        <dependency>
            <groupId>com.softwareloop</groupId>
            <artifactId>mybatis-generator-lombok-plugin</artifactId>
            <version>1.0</version>
        </dependency>
        ...
    </dependencies>
...

Mavenを利用する場合

pom.xmlの<plugin>タグのmybatis-generator-maven-pluginの<dependencies>タグにlombok対応用プラグインを追加します。

pom.xml
...
<plugin>
    <groupId>org.mybatis.generator</groupId>
    <artifactId>mybatis-generator-maven-plugin</artifactId>
    <version>${mybatis.generator.version}</version>
    <configuration>
        <overwrite>true</overwrite>
    </configuration>
    <dependencies>
        <!-- lombok対応プラグイン -->
        <dependency>
            <groupId>com.softwareloop</groupId>
            <artifactId>mybatis-generator-lombok-plugin</artifactId>
            <version>1.0</version>
        </dependency>
        <!-- 以下必要なプラグインを設定 -->
        ...
    </dependencies>
</plugin>
...

コメント出力制御

生成されたコメントの出力制御は、commentGeneratorタグにて行います。

詳しくはこちらにあります。

MyBatis Generatorで出力されるコメント中の日付の出力を抑制したい場合は、以下のように設定します。

generatorConfig.xml
<context ...>
    ...
    <!-- 更新日付を出力しない -->
    <commentGenerator>
      <property name="suppressDate" value="true" />
    </commentGenerator>
    ...

実行のたびに日付が付与され、Diff時に変更のない個所も変更箇所としてピックアップされてしまうことを防ぐことが出来ます。

自動生成されるSQLにスキーマ名が付与されないようにする

こちらに方法が記述されてます。

PostgreSQLだと、以下のような設定となります。

generatorConfig.xml
    ...
    <table schema="public" tableName="%"> 
        <!-- スキーマ名修飾しない -->
        <property name="ignoreQualifiersAtRuntime" value="true" />
    </table>
    ...

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?