Mybatis-generator配置与使用

参考:
https://www.cnblogs.com/throwable/p/12046848.html#table标签
https://www.cnblogs.com/toutou/p/9771404.htm(注解版)
maven配置

<plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.4.0</version>

                <configuration>
                    <!-- 输出详细信息 -->
                    <verbose>true</verbose>
                    <!-- 覆盖生成文件 -->
                    <overwrite>true</overwrite>
                    <!-- 定义配置文件 -->
                    <configurationFile>${basedir}/src/main/resources/generatorConfig.xml</configurationFile>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>5.1.49</version>
                    </dependency>
                </dependencies>
            </plugin>

        </plugins>

generator配置文件

<?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>
  <context id="MysqlTables" targetRuntime="MyBatis3">

    <commentGenerator>
      <property name="suppressDate" value="true"/>
      <!-- 是否去除自动生成的注释 true:是 : false:否 -->
      <property name="suppressAllComments" value="true"/>
    </commentGenerator>

    <!-- jdbc链接信息 -->
    <jdbcConnection driverClass="com.mysql.jdbc.Driver"
      connectionURL="jdbc:mysql://ip地址/数据库?characterEncoding=utf8"
      userId="root" password="root">
    </jdbcConnection>

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

    <!-- 生成PO类的位置 -->
    <javaModelGenerator targetPackage="com.whc.api.po"
      targetProject="src/main/java">
      <property name="enableSubPackages" value="true"/>
      <property name="trimStrings" value="true"/>
    </javaModelGenerator>

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

    <!-- mapper接口生成的位置 -->
    <javaClientGenerator type="ANNOTATEDMAPPER"
      targetPackage="com.whc.api.mapper"
      targetProject="src/main/java">
      <property name="enableSubPackages" value="true"/>
    </javaClientGenerator>

    <!-- 指定要生成的表 -->
    <table tableName="message" domainObjectName="MessagePO"/>
    <table tableName="deleted_message" domainObjectName="DeletedMessagePO"/>
    <table tableName="reply" domainObjectName="ReplyPO"/>
    <table tableName="deleted_reply" domainObjectName="DeletedReplyPO"/>


  </context>
</generatorConfiguration>
posted @   economies  阅读(83)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· Docker 太简单,K8s 太复杂?w7panel 让容器管理更轻松!
点击右上角即可分享
微信分享提示