通用mapper根据多表生成代码

来源:3-11 创建项目-1

Daniyar

2019-07-02

老师,您好!我按您说的配了两个table,但是下面的那个没起作用了
图片描述

写回答

1回答

大目

2019-07-02

您好,刚刚测试了一下,确实是可以的。我的xml:

<!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="generator/config.properties"/>

    <context id="Mysql" targetRuntime="MyBatis3Simple" defaultModelType="flat">
        <property name="beginningDelimiter" value="`"/>
        <property name="endingDelimiter" value="`"/>

        <plugin type="tk.mybatis.mapper.generator.MapperPlugin">
            <property name="mappers" value="tk.mybatis.mapper.common.Mapper"/>
            <property name="caseSensitive" value="true"/>
            <property name="lombok" value="Getter,Setter,ToString"/>
        </plugin>

        <jdbcConnection driverClass="${jdbc.driverClass}"
                        connectionURL="${jdbc.url}"
                        userId="${jdbc.user}"
                        password="${jdbc.password}">
        </jdbcConnection>

        <!--实体-->
        <javaModelGenerator targetPackage="com.itmuch.usercenter.domain.entity.${moduleName}"
                            targetProject="src/main/java"/>

        <!--mapper.xml-->
        <sqlMapGenerator targetPackage="com.itmuch.usercenter.dao.${moduleName}"
                         targetProject="src/main/resources"/>

        <!--mapper接口-->
        <javaClientGenerator targetPackage="com.itmuch.usercenter.dao.${moduleName}"
                             targetProject="src/main/java"
                             type="XMLMAPPER"/>

        <!--为哪张表生成代码-->
        <table tableName="user">
            <generatedKey column="id" sqlStatement="JDBC"/>
        </table>
        <table tableName="bonus_event_log">
            <generatedKey column="id" sqlStatement="JDBC"/>
        </table>
    </context>
</generatorConfiguration>

生成的日志:

....
[INFO] Connecting to the Database
[INFO] Introspecting table user
[INFO] Introspecting table bonus_event_log
[INFO] Generating Record class for table user
[INFO] Generating Mapper Interface for table user
[INFO] Generating SQL Map for table user
[INFO] Generating Record class for table bonus_event_log
[INFO] Generating Mapper Interface for table bonus_event_log
[INFO] Generating SQL Map for table bonus_event_log
[INFO] Saving file UserMapper.xml
[INFO] Saving file BonusEventLogMapper.xml
[INFO] Saving file User.java
[INFO] Saving file UserMapper.java
[INFO] Saving file BonusEventLog.java
[INFO] Saving file BonusEventLogMapper.java
[WARNING] Existing file /Users/itmuch.com/develop/imooc/user-center/src/main/java/com/itmuch/usercenter/dao/user/UserMapper.java was overwritten
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  8.124 s
[INFO] Finished at: 2019-07-02T18:25:56+08:00
[INFO] ------------------------------------------------------------------------

生成的文件:

//img.mukewang.com/szimg/5d1b31a600017ab008220636.jpg

0
2
大目
回复
Daniyar
哈哈 客气啦 祝您学习愉快!另外咱们有技术讨论QQ群的哈,进入到课程的首页,找找就可以看到啦。我每天也都会关注的。
2019-07-02
共2条回复

Spring Cloud Alibaba微服务从入门到进阶

面向未来微服务:熟练掌握Spring Cloud Alibaba

3085 学习 · 1324 问题

查看课程