Intellij IDEA使用Mybatis-generator自动生成数据库表对应的实体类,mapper类以及XML文件

版权声明: https://blog.csdn.net/weixin_40550726/article/details/82945841

项目结构

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="F:\jdbc\mysql-connector-java-5.0.8-bin.jar"/> <!-- 本地驱动位置-->
    <context id="DB2Tables"    targetRuntime="MyBatis3">
        <commentGenerator>
            <property name="suppressDate" value="true"/>
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>
        <!--数据库链接地址账号密码-->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/pblog" userId="root" password="Root">
        </jdbcConnection>
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>
        <!--生成Model类存放位置--><!--targetProject 填入项目存在计算机的位置 -->
        <javaModelGenerator targetPackage="com.njxz.demo.domain" targetProject="E:/IDEAProjects/springbootTest/src/main/java">
            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>
        <!--生成映射文件存放位置-->
        <sqlMapGenerator targetPackage="mapper" targetProject="E:/IDEAProjects/springbootTest/src/main/resources">
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>
        <!--生成Dao类存放位置-->
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.njxz.demo..mapper" targetProject="E:/IDEAProjects/springbootTest/src/main/java">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>
        <!--生成对应表及类名-->
 
        <table tableName="p_user" domainObjectName="User" enableCountByExample="true" enableUpdateByExample="true" enableDeleteByExample="true" enableSelectByExample="true" selectByExampleQueryId="true"></table>



    </context>
</generatorConfiguration>

双击mybatis-generator运行

运行结果

猜你喜欢

转载自blog.csdn.net/weixin_40550726/article/details/82945841