idea生成mybatis实体的方法

  • Post author:
  • Post category:其他


方法一:基于Maven的项

1、配置maven文件,在maven文件添加如下内容

<plugin>
    <groupId>org.mybatis.generator</groupId>
    <artifactId>mybatis-generator-maven-plugin</artifactId>
    <version>1.3.5</version>
    <configuration>
        <!--配置文件的位置-->
<configurationFile>src/main/resources/generatorConfig.xml
        </configurationFile>
        <overwrite>true</overwrite>
        <verbose>true</verbose>
    </configuration>
</plugin>

2、配置生成代码的文件并放在上述配置文件位置的位置

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPEgeneratorConfigurationPUBLIC
"-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
"http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>
    <classPathEntry location="G:\maven\repository\mysql\mysql-connector-java\6.0.6\mysql-connector-java-6.0.6.jar"/>
    <context id="context1" targetRuntime="MyBatis3">

        <commentGenerator>
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>
        <!-- 数据库链接URL、用户名、密码 -->
        <!--<jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost:3306/blog" 
         userId="root" password="root"> -->
<jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
connectionURL="jdbc:mysql://192.168.146.129:3306/oa?useUnicode=true&amp;characterEncoding=utf-8&amp;useSSL=true" userId="oa"
password="061316">
        </jdbcConnection>
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>
        <!-- 生成模型的包名和位置 -->
<javaModelGenerator targetPackage="com.oa.pojo"
targetProject="src">
            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>
        <!-- 生成的映射文件包名和位置 -->
<sqlMapGenerator targetPackage="com.oa.mapping"
targetProject="src">
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>
        <!-- 生成DAO的包名和位置 -->
<javaClientGenerator type="XMLMAPPER"
targetPackage="com.oa.dao" targetProject="src">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>

        <table schema="oa" tableName="person_info" domainObjectName="PersonInfo"
enableCountByExample="false" enableUpdateByExample="false"
enableDeleteByExample="false" enableSelectByExample="false"
selectByExampleQueryId="false"></table>

    </context>
</generatorConfiguration>

3、配置maven运行环境,命令行内容:

mybatis-generator:generate -e



版权声明:本文为qq_41829904原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。