mybatis-generator配置

  • Eclipse安装mybatis-generator插件


    image.png
  • POM插件配置
  1. 新增mybatis依赖
        <dependency>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-core</artifactId>
            <version>1.3.2</version>
        </dependency>
  1. 新增插件依赖
    <plugin>
        <groupId>org.mybatis.generator</groupId>
        <artifactId>mybatis-generator-maven-plugin</artifactId>
        <version>1.3.2</version>
        <configuration>
            <!-- mybatis用于生成代码的配置文件 -->
            <configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
            <verbose>true</verbose>
            <overwrite>true</overwrite>
        </configuration>
    </plugin>
  • 配置mybatis-generator配置文件
    在src/main/resources/下新增文件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>
    <classPathEntry
        location="C:/Program Files (x86)/MySQL/Connector.J 5.1/mysql-connector-java-5.1.41-bin.jar" />
    <context id="my" targetRuntime="MyBatis3">
        <commentGenerator>
            <property name="suppressDate" value="false" />
            <property name="suppressAllComments" value="true" />
        </commentGenerator>
        <!-- mysql数据库连接 -->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
            connectionURL="jdbc:mysql://127.0.0.1:3306/csdndownloader" userId="root"
            password="123456" />

        <!-- 生成model实体类文件位置 -->
        <javaModelGenerator targetPackage="com.chenyq.bean.dto"
            targetProject="wxpay-sdk">
            <property name="enableSubPackages" value="true" />
            <property name="trimStrings" value="true" />
        </javaModelGenerator>

        <!-- 生成mapper.xml配置文件位置 -->
        <sqlMapGenerator targetPackage="com.chenyq.bean.mapping"
            targetProject="wxpay-sdk">
            <property name="enableSubPackages" value="true" />
        </sqlMapGenerator>

        <!-- 生成mapper接口文件位置 -->
        <javaClientGenerator targetPackage="com.chenyq.bean.mapper"
            targetProject="wxpay-sdk"
            type="XMLMAPPER">
            <property name="enableSubPackages" value="true" />
        </javaClientGenerator>
        <!-- 需要生成的实体类对应的表名,多个实体类复制多份该配置即可 -->
        <table tableName="t_account" domainObjectName="Account"
            enableCountByExample="false" enableUpdateByExample="false"
            enableDeleteByExample="false" enableSelectByExample="false"
            selectByExampleQueryId="false">
        </table>
        <table tableName="t_file" domainObjectName="CSDNFile"
            enableCountByExample="false" enableUpdateByExample="false"
            enableDeleteByExample="false" enableSelectByExample="false"
            selectByExampleQueryId="false">
        </table>
        <table tableName="t_order" domainObjectName="Order"
            enableCountByExample="false" enableUpdateByExample="false"
            enableDeleteByExample="false" enableSelectByExample="false"
            selectByExampleQueryId="false">
        </table>

    </context>
</generatorConfiguration>
  • 生成代码
  1. 在Eclipse中选中generatorConfig.xml右键选中执行
  2. 执行maven命令:
mvn mybatis-generator:generate

经过测试,插件配置中targetProject在命令行执行时,应当使用src/main/java

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容