IntelliJ IDEA中使用mybatis-generator

使用步骤

  • 一、新建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>
    <!-- 引入配置文件 -->
    <!--TODO 注意!!!自动生成代码 要把这句放开,链接数据库-->
   <properties resource="jdbc.properties"/>
    <!-- 指定数据连接驱动jar地址 -->
     <classPathEntry location="F:\SVN_Info\cloudTree\trustzhyq\src\e3izm\src\main\webapp\WEB-INF\lib\mysql-connector-java-5.1.29.jar"/>

    <context id="context" targetRuntime="MyBatis3">
        <commentGenerator>
            <!-- 是否去除自动生成的注释 true:是 : false:否 -->
            <property name="suppressAllComments" value="true"/>
            <property name="suppressDate" value="true"/>
        </commentGenerator>
        <!-- 数据库的相关配置 -->
        <jdbcConnection driverClass="${driverClasss}" connectionURL="${jdbcUrl}"
                        userId="${username}" password="${password}"/>

        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>

        <!-- 实体类生成的位置 -->
        <javaModelGenerator targetPackage="com.trust.e3izm.ressvc.entity" targetProject="src/main/java">
            <property name="enableSubPackages" value="false"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>

        <!-- *Mapper.xml 文件的位置 ,targetPackage:包名,targetProject:项目下的路径-->
        <sqlMapGenerator targetPackage="ressvc" targetProject="src/main/resources/mapper">
            <property name="enableSubPackages" value="false"/>
        </sqlMapGenerator>

        <!-- Mapper 接口文件的位置 -->
        <javaClientGenerator targetPackage="com.trust.e3izm.ressvc.dao" targetProject="src/main/java" type="XMLMAPPER">
            <property name="enableSubPackages" value="false"/>
        </javaClientGenerator>

        <!-- 配置表信息 -->
        <!--第三方服务类型-->
        <table schema="e3iz" tableName="THIRDPTYSVC_TYPE"
               domainObjectName="Thirdptysvc_type" enableCountByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false"
               enableUpdateByExample="false">
        </table>
         <!--xxtable-->
        <!--如果生成n个表,那就将上面的那段table代码copy n份-->
            </context>
</generatorConfiguration>
  • 二、在pom.xml导入依赖包
<plugins>
            <plugin>
                <!--Mybatis-generator插件,用于自动生成Mapper和POJO-->
                <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>
                <executions>
                    <execution>
                        <id>Generate MyBatis Artifacts</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.mybatis.generator</groupId>
                        <artifactId>mybatis-generator-core</artifactId>
                        <version>1.3.2</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>

注意
1.这段代码要放到

 <build>
        <finalName>e3izm</finalName>
         <!-- 将上面这段代码放到pom.xml文件的这个位置-->
    </build>

2.maven2下载关于generator,maven依赖包下载不下来,需要更改为maven3才能下载下来

maven3更改.png

 

  • 三、新建maven运行器

     

    maven.png

<!-- 配置的运行命令-->
mybatis-generator:generate -e

好了,大功告成,运行maven运行器即可!



作者:瑾兰
链接:https://www.jianshu.com/p/d019c9880d25
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值