1 Star 1 Fork 0

初学者 / mybatis-generator-lombok

Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Without author's permission, this code is only for learning and cannot be used for other purposes.
Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

mybatis-generator-lombok

A plugin for MyBatis Generator to use Lombok annotations instead of getters and setters

Maven依赖

<dependency>
    <groupId>com.seejoke</groupId>
    <artifactId>mybatis-generator-lombok</artifactId>
    <version>1.0</version>
</dependency>

MyBatis Generator Lombok plugin and Comment

实现的功能

主要整合了lombok插件实现getter/setter等通用方法的自动生成,同时自定义实现了一个注释生成器, 通过抓取数据库表里面的注释作为实体类的注释内容。

插件的用法

如果你想在你的maven中使用,将下面的plugin xml脚本复制到你的pom.xml中即可,下面详细提供了配置的用法

<plugin>
    <groupId>org.mybatis.generator</groupId>
    <artifactId>mybatis-generator-maven-plugin</artifactId>
    <version>1.3.6</version>
    <dependencies>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql-connector-java.version}</version>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>tk.mybatis</groupId>
            <artifactId>mapper</artifactId>
            <version>4.0.2</version>
        </dependency>
        <dependency>
            <groupId>com.seejoke</groupId>
            <artifactId>mybatis-generator-lombok</artifactId>
            <version>1.0</version>
        </dependency>
    </dependencies>
    <executions>
        <execution>
            <id>Generate MyBatis Artifacts</id>
            <phase>package</phase>
            <goals>
                <goal>generate</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <verbose>true</verbose>
        <overwrite>true</overwrite>
        <configurationFile>src/main/resources/mybatis-generator.xml</configurationFile>
    </configuration>
</plugin>

同时添加配置文件generatorConfig.xml,使用的时候请根据项目需要自行修改对应配置



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
        PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
        "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
    <!--加载配置文件,为下面读取数据库信息准备-->
    <properties resource="data.properties"/>

    <context id="default" targetRuntime="MyBatis3Simple" defaultModelType="flat">

        <!-- 生成的Java文件的编码 -->
        <property name="javaFileEncoding" value="UTF-8"/>

        <!-- 格式化java代码 -->
        <property name="javaFormatter" value="org.mybatis.generator.api.dom.DefaultJavaFormatter"/>
        <!-- 格式化XML代码 -->
        <property name="xmlFormatter" value="org.mybatis.generator.api.dom.DefaultXmlFormatter"/>

        <property name="beginningDelimiter" value="`"/>
        <property name="endingDelimiter" value="`"/>

        <plugin type="tk.mybatis.mapper.generator.MapperPlugin">
            <property name="mappers" value="tk.mybatis.mapper.common.Mapper"/>
            <!--caseSensitive默认false,当数据库表名区分大小写时,可以将该属性设置为true-->
            <property name="caseSensitive" value="true"/>
        </plugin>

      <plugin type="com.seejoke.mybatis.generator.plugins.LombokPlugin">
        <property name="hasLombok" value="true"/>
      </plugin>

        <!-- 生成 JavaBean 对象继承 Serializable 类 -->
        <plugin type="org.mybatis.generator.plugins.SerializablePlugin"/>

        <!-- 阻止生成自动注释 -->
        <commentGenerator>
            <property name="javaFileEncoding" value="UTF-8"/>
            <property name="suppressDate" value="true"/>
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>

        <!--数据库链接地址账号密码-->
        <jdbcConnection driverClass="${spring.datasource.driver-class-name}"
                        connectionURL="${spring.datasource.url}"
                        userId="${spring.datasource.username}"
                        password="${spring.datasource.password}">
        </jdbcConnection>

        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>

        <!--生成Model类存放位置-->
      <javaModelGenerator targetPackage="com.seejoke.boss.entity" targetProject="src/main/java">
            <!--<property name="constructorBased" value="false"/>-->
            <property name="useActualColumnNames" value="true"/>
            <property name="enableSubPackages" value="true"/>

            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="true"/>
            <!-- 给Model添加一个父类 -->
        <property name="rootClass" value="com.seejoke.freemarker.entity.BaseEntity"/>
        </javaModelGenerator>

        <!--生成映射文件存放位置-->
        <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources">
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>

        <!--生成mapper类存放位置-->
      <javaClientGenerator type="XMLMAPPER" targetPackage="com.seejoke.boss.mapper"
                             targetProject="src/main/java">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>

        <!--生成对应表及类名 -->
      <table tableName="tb_user" domainObjectName="User">
        <property name="useActualColumnNames" value="true"/>
      </table>
      <table tableName="tb_log" domainObjectName="Log"></table>
    </context>
</generatorConfiguration>

Ider操作界面如图

image

Author

Comments ( 1 )

Sign in for post a comment

About

A plugin for MyBatis Generator to use Lombok annotations instead of getters and setters spread retract
Cancel

Releases

No release

Contributors

All

Activities

load more
can not load any more
Java
1
https://git.oschina.net/diaodiaofly/mybatis-generator-lombok.git
git@git.oschina.net:diaodiaofly/mybatis-generator-lombok.git
diaodiaofly
mybatis-generator-lombok
mybatis-generator-lombok
master

Search

103611 48b8ff67 1899542 103622 4d02230c 1899542