0
点赞
收藏
分享

微信扫一扫

使用mybatisgenerator生产mybatis的entity和example和mapper等

青乌 2023-08-19 阅读 49


项目名称mybatisgenerator

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.cqsym</groupId>
    <artifactId>mybatisgenerator</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>2.6.14</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <!--lombok -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.5.9</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
<!--            <version>5.1.46</version>-->
            <version>8.0.30</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.mybatis.generator/mybatis-generator-core -->
        <dependency>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-core</artifactId>
            <version>1.4.2</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.mybatis.generator/mybatis-generator-maven-plugin -->
        <dependency>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-maven-plugin</artifactId>
            <version>1.4.2</version>
        </dependency>


    </dependencies>
    <build>
        <plugins>
            <plugin>
                <!--Mybatis-generator插件,用于自动生成Mapper和entuty-->
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.4.2</version>
                <configuration>
                    <!--配置文件的位置-->
                    <configurationFile>src/main/resources/mybatis-generator-config.xml</configurationFile>
                    <verbose>true</verbose>
                    <overwrite>true</overwrite>
                </configuration>
                <executions>
                    <execution>
                        <id>Generate MyBatis Artifacts</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>5.1.46</version>
                    </dependency>
                    <!--生成代码插件-->
                    <dependency>
                        <groupId>org.mybatis.generator</groupId>
                        <artifactId>mybatis-generator-core</artifactId>
                        <version>1.4.2</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

</project>


使用的命令是:

mvn mybatis-generator:generate -e

出现的问题,使用mysql驱动版本和jdbc_driver驱动名字编写需要注意:
如果是8.0.30选择驱动com.mysql.cj.jdbc.Driver运行会报找不到驱动
如果换成5.1.46选择驱动com.mysql.jdbc.Driver则没有任何问题
如果换成8.0.30选择驱动com.mysql.jdbc.Driver则没有任何问题



mybatis-generator-config-bak001.xml-bak(都是备份的,使用的不是这个)

<?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="mysql-connector-java-8.0.30.jar"/>
    <context id="context" targetRuntime="MyBatis3">
        <commentGenerator>
            <property name="suppressAllComments" value="true"/>
            <property name="suppressDate" value="true"/>
        </commentGenerator>
        <!-- 数据库的相关配置 -->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://47.101.66.144:3306/twms" userId="root" password="root__123AbCdHjKl"/>
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>
        <!-- 实体类生成的位置 -->
        <javaModelGenerator targetPackage="com.cqsym.mulmbds.entity.seconedaryentity" targetProject="src/main/java">
            <property name="enableSubPackages" value="false"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>
        <!-- *Mapper.xml 文件的位置 -->
        <sqlMapGenerator targetPackage="mapper/seconedary" targetProject=".\src\main\resources">
            <property name="enableSubPackages" value="false"/>
        </sqlMapGenerator>
        <!-- Mapper接口文件的位置 -->
        <javaClientGenerator targetPackage="com.cqsym.mulmbds.mapper.secondarymapper" targetProject="src/main/java" type="XMLMAPPER">
            <property name="enableSubPackages" value="false"/>
        </javaClientGenerator>
        <!-- 相关表的配置 -->
        <table tableName="t_order" domainObjectName="TOrder"  enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="false"  enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/>
        <table tableName="t_customer" domainObjectName="TCustomer" enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="false"  enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/>
    </context>
</generatorConfiguration>

这个也是xml的配置文件

mybatis-generator-config-bak000.xml-bak(都是备份的,使用的不是这个)

<?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="context" targetRuntime="MyBatis3">
        <commentGenerator>
            <property name="suppressAllComments" value="true"/>
            <property name="suppressDate" value="true"/>
        </commentGenerator>
        <!-- 数据库的相关配置 -->
        <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver" connectionURL="jdbc:mysql://47.101.66.144:3306/twms?useUnicode=true;characterEncoding=utf-8" userId="root" password="root__123AbCdHjKl"/>
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>
        <!-- 实体类生成的位置 -->
        <javaModelGenerator targetPackage="com.cqsym.mulmbds.entity.seconedaryentity" targetProject="src/main/java">
            <property name="enableSubPackages" value="false"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>
        <!-- *Mapper.xml 文件的位置 -->
        <sqlMapGenerator targetPackage="mapper/seconedary" targetProject=".\src\main\resources">
            <property name="enableSubPackages" value="false"/>
        </sqlMapGenerator>
        <!-- Mapper接口文件的位置 -->
        <javaClientGenerator targetPackage="com.cqsym.mulmbds.mapper.secondarymapper" targetProject="src/main/java" type="XMLMAPPER">
            <property name="enableSubPackages" value="false"/>
        </javaClientGenerator>
        <!-- 相关表的配置 -->
        <table tableName="factor_result" domainObjectName="FactorResult"  enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="false"  enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/>
        <table tableName="factor_weight" domainObjectName="FactorWeight" enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="false"  enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/>
        <table tableName="factor_score" domainObjectName="FactorScore" enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="false"  enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/>
        <table tableName="extra_factor_score" domainObjectName="ExtraFactorScore" enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="false"  enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/>
    </context>
</generatorConfiguration>


mybatis-generator-config.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="mysql-connector-java-8.0.30.jar"/>
    <context id="context" targetRuntime="MyBatis3">
        <commentGenerator>
            <property name="suppressAllComments" value="true"/>
            <property name="suppressDate" value="true"/>
        </commentGenerator>
        <!-- 数据库的相关配置 -->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://47.101.66.144:3306/twms" userId="root" password="root__123AbCdHjKl"/>
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>
        <!-- 实体类生成的位置 -->
        <javaModelGenerator targetPackage="com.cqsym.rdtwms.entity" targetProject="src/main/java">
            <property name="enableSubPackages" value="false"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>
        <!-- *Mapper.xml 文件的位置 -->
        <sqlMapGenerator targetPackage="mapper" targetProject=".\src\main\resources">
            <property name="enableSubPackages" value="false"/>
        </sqlMapGenerator>
        <!-- Mapper接口文件的位置 -->
        <javaClientGenerator targetPackage="com.cqsym.rdtwms.mapper" targetProject="src/main/java" type="XMLMAPPER">
            <property name="enableSubPackages" value="false"/>
        </javaClientGenerator>
        <!-- 相关表的配置 -->
        <table tableName="aliyun_notify_log" domainObjectName="AliyunNotifyLog" enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="true"  enableDeleteByExample="true" enableSelectByExample="true" enableUpdateByExample="true"/>
        <table tableName="aliyun_notify_template" domainObjectName="AliyunNotifyTemplate" enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="true"  enableDeleteByExample="true" enableSelectByExample="true" enableUpdateByExample="true"/>
        <table tableName="aliyun_sms_log" domainObjectName="AliyunSmsLog" enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="true"  enableDeleteByExample="true" enableSelectByExample="true" enableUpdateByExample="true"/>
        <table tableName="aliyun_sms_template" domainObjectName="AliyunSmsTemplate" enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="true"  enableDeleteByExample="true" enableSelectByExample="true" enableUpdateByExample="true"/>
        <table tableName="auth_application" domainObjectName="AuthApplication" enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="true"  enableDeleteByExample="true" enableSelectByExample="true" enableUpdateByExample="true"/>
        <table tableName="auth_dept" domainObjectName="AuthDept" enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="true"  enableDeleteByExample="true" enableSelectByExample="true" enableUpdateByExample="true"/>
        <table tableName="auth_password_rules" domainObjectName="AuthPasswordRules" enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="true"  enableDeleteByExample="true" enableSelectByExample="true" enableUpdateByExample="true"/>
        <table tableName="auth_resource" domainObjectName="AuthResource" enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="true"  enableDeleteByExample="true" enableSelectByExample="true" enableUpdateByExample="true"/>
        <table tableName="auth_role" domainObjectName="AuthRole" enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="true"  enableDeleteByExample="true" enableSelectByExample="true" enableUpdateByExample="true"/>
        <table tableName="auth_role_resource" domainObjectName="AuthRoleResource" enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="true"  enableDeleteByExample="true" enableSelectByExample="true" enableUpdateByExample="true"/>
        <table tableName="auth_user" domainObjectName="AuthUser" enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="true"  enableDeleteByExample="true" enableSelectByExample="true" enableUpdateByExample="true"/>
        <table tableName="auth_user_dept" domainObjectName="AuthUserDept" enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="true"  enableDeleteByExample="true" enableSelectByExample="true" enableUpdateByExample="true"/>
        <table tableName="auth_user_password_log" domainObjectName="AuthUserPasswordLog" enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="true"  enableDeleteByExample="true" enableSelectByExample="true" enableUpdateByExample="true"/>
        <table tableName="auth_user_role" domainObjectName="AuthUserRole" enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="true"  enableDeleteByExample="true" enableSelectByExample="true" enableUpdateByExample="true"/>
        <table tableName="bi_income_detail" domainObjectName="BiIncomeDetail" enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="true"  enableDeleteByExample="true" enableSelectByExample="true" enableUpdateByExample="true"/>
        <table tableName="bi_income_detail_contrast" domainObjectName="BiIncomeDetailContrast" enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="true"  enableDeleteByExample="true" enableSelectByExample="true" enableUpdateByExample="true"/>
        <table tableName="operate_log" domainObjectName="OperateLog" enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="true"  enableDeleteByExample="true" enableSelectByExample="true" enableUpdateByExample="true"/>

        <table tableName="t_driver" domainObjectName="TDriver" enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="true"  enableDeleteByExample="true" enableSelectByExample="true" enableUpdateByExample="true"/>
        <table tableName="t_driver_bank" domainObjectName="TDriverBank" enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="true"  enableDeleteByExample="true" enableSelectByExample="true" enableUpdateByExample="true"/>
        <table tableName="t_driver_bind" domainObjectName="TDriverBind" enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="true"  enableDeleteByExample="true" enableSelectByExample="true" enableUpdateByExample="true"/>
        <table tableName="t_driver_card" domainObjectName="TDriverCard" enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="true"  enableDeleteByExample="true" enableSelectByExample="true" enableUpdateByExample="true"/>

        <table tableName="t_expend_accounting" domainObjectName="TExpendAccounting" enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="true"  enableDeleteByExample="true" enableSelectByExample="true" enableUpdateByExample="true"/>
        <table tableName="t_expend_accounting_detail" domainObjectName="TExpendAccountingDetail" enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="true"  enableDeleteByExample="true" enableSelectByExample="true" enableUpdateByExample="true"/>
        
        <table tableName="t_income_cost" domainObjectName="TIncomeCost" enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="true"  enableDeleteByExample="true" enableSelectByExample="true" enableUpdateByExample="true"/>
        <table tableName="t_location" domainObjectName="TLocation" enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="true"  enableDeleteByExample="true" enableSelectByExample="true" enableUpdateByExample="true"/>
        <table tableName="t_location_group" domainObjectName="TLocationGroup" enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="true"  enableDeleteByExample="true" enableSelectByExample="true" enableUpdateByExample="true"/>

        <table tableName="t_order" domainObjectName="TOrder" enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="true"  enableDeleteByExample="true" enableSelectByExample="true" enableUpdateByExample="true"/>
        <table tableName="t_order_customer" domainObjectName="TOrderCustomer" enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="true"  enableDeleteByExample="true" enableSelectByExample="true" enableUpdateByExample="true"/>
        <table tableName="t_order_log" domainObjectName="TOrderLog" enableInsert="true" enableDeleteByPrimaryKey="true" enableUpdateByPrimaryKey="true" enableSelectByPrimaryKey="true" enableCountByExample="true"  enableDeleteByExample="true" enableSelectByExample="true" enableUpdateByExample="true"/>
       
    </context>
</generatorConfiguration>


使用mybatisgenerator生产mybatis的entity和example和mapper等_java


https://gitee.com/lenglingx/mybatisgenerator


举报

相关推荐

0 条评论