springboot+maven+mybatis 多模块项目中使用maven的generator生成器

其实很简单

想看目录结构

springboot+maven+mybatis 多模块项目中使用maven的generator生成器

blog-dao就是我的数据库连接层.

1 引入mybatis-generator-maven-plugin

<plugin>
    <groupId>org.mybatis.generator</groupId>
    <artifactId>mybatis-generator-maven-plugin</artifactId>
    <version>1.3.2</version>
    <configuration>                                
        <configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
        <verbose>true</verbose>
        <overwrite>true</overwrite>
    </configuration>
</plugin>

2  generator.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>
    <!-- mysql 连接包 -->
    <classPathEntry location="C:/Users/87211/.m2/repository/mysql/mysql-connector-java/5.1.29/mysql-connector-java-5.1.29.jar" />
    <context id="test" targetRuntime="MyBatis3">
        <plugin type="org.mybatis.generator.plugins.EqualsHashCodePlugin"></plugin>
        <plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin>
        <plugin type="org.mybatis.generator.plugins.ToStringPlugin"></plugin>
        <commentGenerator>
            <!-- 这个元素用来去除指定生成的注释中是否包含生成的日期 false:表示保护 -->
            <!-- 如果生成日期,会造成即使修改一个字段,整个实体类所有属性都会发生变化,不利于版本控制,所以设置为true -->
            <property name="suppressDate" value="true" />
            <property name="javaFileEncoding" value="UTF-8"/>
            <!-- 是否去除自动生成的注释 true:是 : false:否 -->
            <property name="suppressAllComments" value="false" />
        </commentGenerator>
        <!--数据库链接URL,用户名、密码 -->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/mydb" userId="root" password="root">
        </jdbcConnection>
        <javaTypeResolver>
            <!-- This property is used to specify whether MyBatis Generator should
             force the use of java.math.BigDecimal for DECIMAL and NUMERIC fields, -->
            <property name="forceBigDecimals" value="false" />
        </javaTypeResolver>
        <!-- 生成模型的包名和位置 文件夹自己定义-->
        <javaModelGenerator targetPackage="com.xjs.entity"
                            targetProject="src/main/java">
        </javaModelGenerator>
        <!-- 生成映射文件的包名和位置 文件夹自己定义-->
        <sqlMapGenerator targetPackage="mapper"
                         targetProject="src/main/resources/">
        </sqlMapGenerator>
        <!-- 生成DAO的包名和位置 文件夹自己定义-->
        <javaClientGenerator targetPackage="com.xjs.mapper"
                             targetProject="src/main/java"
                             type="XMLMAPPER"/>

        <!-- 要生成哪些表 -->
        <table tableName="blog_b_article" schema="boot" enableCountByExample="false"
               enableUpdateByExample="false" enableDeleteByExample="false"
               enableSelectByExample="false" selectByExampleQueryId="false">
            <!--<property name="useActualColumnNames" value="true"/>-->
            <generatedKey column="id" sqlStatement="MySql" identity="true"/>
        </table>
        <table tableName="blog_b_comment" schema="boot" enableCountByExample="false"
               enableUpdateByExample="false" enableDeleteByExample="false"
               enableSelectByExample="false" selectByExampleQueryId="false">
            <!--<property name="useActualColumnNames" value="true"/>-->
            <generatedKey column="id" sqlStatement="MySql" identity="true"/>
        </table>
        <table tableName="blog_b_comment_detail" schema="boot" enableCountByExample="false"
               enableUpdateByExample="false" enableDeleteByExample="false"
               enableSelectByExample="false" selectByExampleQueryId="false">
            <!--<property name="useActualColumnNames" value="true"/>-->
            <generatedKey column="id" sqlStatement="MySql" identity="true"/>
        </table>
        <table tableName="blog_b_personal_classification" schema="boot" enableCountByExample="false"
               enableUpdateByExample="false" enableDeleteByExample="false"
               enableSelectByExample="false" selectByExampleQueryId="false">
            <!--<property name="useActualColumnNames" value="true"/>-->
            <generatedKey column="id" sqlStatement="MySql" identity="true"/>
        </table>
        <table tableName="blog_b_personal_classification_detail" schema="boot" enableCountByExample="false"
               enableUpdateByExample="false" enableDeleteByExample="false"
               enableSelectByExample="false" selectByExampleQueryId="false">
            <!--<property name="useActualColumnNames" value="true"/>-->
            <generatedKey column="id" sqlStatement="MySql" identity="true"/>
        </table>
        <table tableName="blog_sys_user" schema="boot" enableCountByExample="false"
               enableUpdateByExample="false" enableDeleteByExample="false"
               enableSelectByExample="false" selectByExampleQueryId="false">
            <!--<property name="useActualColumnNames" value="true"/>-->
            <generatedKey column="id" sqlStatement="MySql" identity="true"/>
        </table>
    </context>
</generatorConfiguration>

只需要这两个步骤就搞定了,当然你的实体 mapper xml这几个包最好都在数据库连接层这个module里面,generator.xml里面的配置都有备注,里面没有备注的一些属性请自行百度.

3  

springboot+maven+mybatis 多模块项目中使用maven的generator生成器

 然后再点一下这个就好了,

springboot+maven+mybatis 多模块项目中使用maven的generator生成器