mybatis自动生成mapper文件

1.pom的plugins里配置:

<plugin>
<groupId>org.mybatis.generator</groupId>
<artifactId>mybatis-generator-maven-plugin</artifactId>
<version>1.3.2</version>

</plugin>

2.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>
<!--DRIVER-->
    <classPathEntry location="C:\Users\Administrator\.m2\repository\mysql\mysql-connector-java\5.1.39\mysql-connector-java-5.1.39.jar"/>
  <context id="context1">
    <!--  <jdbcConnection connectionURL="???" driverClass="???" password="???" userId="???" />
    <javaModelGenerator targetPackage="???" targetProject="???" />
    <sqlMapGenerator targetPackage="???" targetProject="???" />
    <javaClientGenerator targetPackage="???" targetProject="???" type="XMLMAPPER" />
    <table schema="???" tableName="???">
      <columnOverride column="???" property="???" />
    </table>-->
    
    <!--DATABASE URL-->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://ip:3306/MIS_PAAS" userId="root" password="">
        </jdbcConnection>
    <!--MODEL-->
        <javaModelGenerator targetPackage="rest.mybatis.model.passModel" targetProject="C:\Users\Administrator\git\mispass\src\main\java">
            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>
        <!--MAPPER-->
        <sqlMapGenerator targetPackage="rest.mybatis.mapping.passMapping" targetProject="C:\Users\Administrator\git\mispass\src\main\resources">
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>
        <!--DAO-->
        <javaClientGenerator type="XMLMAPPER" targetPackage="rest.mybatis.dao.passDao" targetProject="C:\Users\Administrator\git\mispass\src\main\java">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>
        <!--TABELS AND NAME-->
        
<table schema="MIS_PAAS" tableName="PAAS_TEMPLATE" domainObjectName="PaasTemplate" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table schema="MIS_PAAS" tableName="PAAS_TEMPLATE_FILE" domainObjectName="PaasTemplateFile" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table schema="MIS_PAAS" tableName="PAAS_SUBSERVICE" domainObjectName="PaasSubservice" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table schema="MIS_PAAS" tableName="PAAS_ORDER" domainObjectName="PaasOrder" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table schema="MIS_PAAS" tableName="PAAS_INSTANCE" domainObjectName="PaasInstance" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
<table schema="MIS_PAAS" tableName="PAAS_ORD_TENANT_ORG_R" domainObjectName="PaasOrdTenantOrgR" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>


<table schema="DY_PMIS" tableName="UserT" domainObjectName="PassUser" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
  </context>

</generatorConfiguration>

3.右击generatorConfig,run as——>run configurations——》maven build,新建

base directory:${workspace_loc:/pass}

goals:mybatis-generator:generate



或者使用命令行方式生成映射文件:

mybatis-generator-core-1.3.5\lib,下面需要有数据库驱动jar

配置文件写好以后,打开cmd,将目录切换到lib目录下,执行脚本:java -jar mybatis-generator-core-1.3.2.jar -configfile generatorConfig.xml -overwrite

猜你喜欢

转载自blog.csdn.net/u014161595/article/details/80907942