抱歉,您的浏览器无法访问本站

本页面需要浏览器支持(启用)JavaScript


了解详情 >

MyBatis逆向生成工具

添加依赖

<!-- mybatis -->
<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>2.1.3</version>
</dependency>
<!-- 通用mapper逆向工具 -->
<dependency>
    <groupId>tk.mybatis</groupId>
    <artifactId>mapper-spring-boot-starter</artifactId>
    <version>2.1.5</version>
</dependency>

添加maven插件

<!-- mybatis generator 自动生成代码插件 -->
<plugin>
    <groupId>org.mybatis.generator</groupId>
    <artifactId>mybatis-generator-maven-plugin</artifactId>
    <version>1.4.0</version>
    <configuration>
        <configurationFile>../config/generator/generatorConfig.xml</configurationFile>
        <overwrite>true</overwrite>
        <verbose>true</verbose>
    </configuration>
    <dependencies>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.18</version>
        </dependency>
        <dependency>
            <groupId>tk.mybatis</groupId>
            <artifactId>mapper</artifactId>
            <version>4.1.5</version>
        </dependency>
        <!-- 注意版本,用1.4.0会报找不到某个类的错误 -->
        <dependency>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-core</artifactId>
            <version>1.3.7</version>
        </dependency>
    </dependencies>
</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>
    <context id="Mysql" targetRuntime="MyBatis3Simple" defaultModelType="flat">

<!--        <property name="autoDelimitKeywords" value="true" />-->
        <property name="beginningDelimiter" value="`" />
        <property name="endingDelimiter" value="`" />

        <!-- 覆盖生成XML文件 -->
        <plugin type="org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin" />
        <!-- 生成的实体类添加toString()方法 -->
        <plugin type="org.mybatis.generator.plugins.ToStringPlugin" />

        <!-- 不生成注释 -->
        <!--        <commentGenerator>-->
        <!--            <property name="suppressAllComments" value="true" />-->
        <!--        </commentGenerator>-->

        <!-- 通用mapper所在目录 -->
        <plugin type="tk.mybatis.mapper.generator.MapperPlugin">
            <property name="mappers" value="org.lgq.my.mapper.MyMapper"/>
        </plugin>

        <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/dev" userId="root"
            password="lgq51233" />

        <!-- pojo类的位置 -->
        <javaModelGenerator targetProject="..\dev-pojo\src\main\java" targetPackage="org.lgq.pojo" />

        <!-- mapper xml的位置 -->
        <sqlMapGenerator targetProject="..\dev-mapper\src\main\resources" targetPackage="mapper" />

        <!-- mapper类的位置 -->
        <javaClientGenerator targetProject="..\dev-mapper\src\main\java" targetPackage="org.lgq.mapper" type="XMLMAPPER" />

        <!-- 数据库表 -->
        <!--        <table tableName="carousel" domainObjectName="CourseContent" />-->
        <!-- 表名相同,生成不是目标表的问题。添加 catalog schema 属性指定数据库名 
             注意添加 ignoreQualifiersAtRuntime 属性,设置为 true, 否则生成的文件中会包含
             catalog和schema相关的内容,导致sql语句执行有问题
        -->
        <table tableName="carousel" catalog="dev">
            <property name="ignoreQualifiersAtRuntime" value="true" />
        </table>
        <table tableName="category" catalog="dev">
            <property name="ignoreQualifiersAtRuntime" value="true" />
        </table>
        <table tableName="items" catalog="dev">
            <property name="ignoreQualifiersAtRuntime" value="true" />
        </table>
        <table tableName="items_comments" catalog="dev">
            <property name="ignoreQualifiersAtRuntime" value="true" />
        </table>
        <table tableName="items_param" catalog="dev">
            <property name="ignoreQualifiersAtRuntime" value="true" />
        </table>
        <table tableName="items_spec" catalog="dev" >
            <property name="ignoreQualifiersAtRuntime" value="true"/>
        </table>
        <table tableName="order_items" catalog="dev" >
            <property name="ignoreQualifiersAtRuntime" value="true"/>
        </table>
        <table tableName="order_status" catalog="dev" >
            <property name="ignoreQualifiersAtRuntime" value="true"/>
        </table>
        <table tableName="orders" catalog="dev" >
            <property name="ignoreQualifiersAtRuntime" value="true"/>
        </table>
        <table tableName="stu" catalog="dev" >
            <property name="ignoreQualifiersAtRuntime" value="true"/>
        </table>
        <table tableName="user_address" catalog="dev" >
            <property name="ignoreQualifiersAtRuntime" value="true"/>
        </table>
        <table tableName="users" catalog="dev" >
            <property name="ignoreQualifiersAtRuntime" value="true"/>
        </table>

    </context>
</generatorConfiguration>

idea添加执行命令配置

评论