SpringBoot 整合 Mybatis 逆向工程

前提:springboot已经整合了mybatis,具体过程参见我另一篇:springboot整合mybatis详细教程

一.pom.xml

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

在这里插入图片描述

二.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>
    <!-- 数据库驱动:选择你的本地硬盘上面的数据库驱动包-->
    <classPathEntry location="D:/Maven/maven_repository/mysql/mysql-connector-java/5.1.6/mysql-connector-java-5.1.6.jar"/>
    
    <context id="DB2Tables" targetRuntime="MyBatis3">
        <commentGenerator>
            <property name="suppressAllComments" value="true"/>
            <property name="suppressDate" value="true"/>
            <property name="addRemarkComments" value="true"/>
        </commentGenerator>
        
        <!--数据库链接URL,用户名、密码 -->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver" userId="root" password="123456"
                        connectionURL="jdbc:mysql://127.0.0.1:3306/day21" >
        </jdbcConnection>
        
        <!-- 类型转换 -->
        <javaTypeResolver >
            <!-- 是否使用bigDecimal,
                false: 把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer(默认)
                true:  把JDBC DECIMAL 和 NUMERIC 类型解析为java.math.BigDecimal
            -->
            <property name="forceBigDecimals" value="true" />
        </javaTypeResolver>


        <!-- 生成模型的包名和位置-->
        <javaModelGenerator targetPackage="com.jd.lean.mjp.dal.entity" targetProject="src/main/java">
            <property name="enableSubPackages" value="true" />
            <property name="trimStrings" value="true" />
        </javaModelGenerator>


        <!-- 生成映射文件即Mapper.xml的包名和位置-->
        <sqlMapGenerator targetPackage="com.jd.lean.mjp.dal.mapper" targetProject="src/main/resources">
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>


        <!-- 生成DAO接口即Mapper接口的包名和位置-->
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.jd.lean.mjp.dal.mapper" targetProject="src/main/java">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>


        <!-- 要生成的表 tableName是数据库中的表名或视图名 domainObjectName是实体类名-->
        <!-- <table tableName="risk_model_order" domainObjectName="DSRiskModelOrder" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
         <table tableName="tel_bill_record" domainObjectName="DSTelBillRecord" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>-->
        <table tableName="tb_user" domainObjectName="UserPO" >
        </table>
    </context>
</generatorConfiguration>

在这里插入图片描述在这里插入图片描述

三.执行

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/tmax52HZ/article/details/118323119