Intelij在maven安装mybatis代码自动生成器插件

情景介绍
编写代码的过程中,我们总希望能有一个插件能快速生成公用的相似的代码。感觉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>  
<!-- ���ݿ�����-->  
    <classPathEntry  location="E:\MavenRepository\mysql\mysql-connector-java\5.1.30\mysql-connector-java-5.1.30.jar"/>
    <context id="DB2Tables"  targetRuntime="MyBatis3">  
        <commentGenerator>  
            <property name="suppressDate" value="true"/>  
            <!-- �Ƿ�ȥ���Զ����ɵ�ע�� true���� �� false:�� -->  
            <property name="suppressAllComments" value="true"/>  
        </commentGenerator>  
        <!--���ݿ�����URL���û��������� -->  
        <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://127.0.0.1/mybatis" userId="root" password="root">
        </jdbcConnection>  
        <javaTypeResolver>  
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>  
        <!-- ����ģ�͵İ�����λ��-->  
        <javaModelGenerator targetPackage="com.neusoft.domain" targetProject="src/main/java">
            <property name="enableSubPackages" value="true"/>  
            <property name="trimStrings" value="true"/>  
        </javaModelGenerator>  
        <!-- ����ӳ���ļ��İ�����λ��-->  
        <sqlMapGenerator targetPackage="com.neusoft.mapper" targetProject="src/main/java">
            <property name="enableSubPackages" value="true"/>  
        </sqlMapGenerator>  
        <!-- ����DAO�İ�����λ��-->  
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.neusoft.mapper" targetProject="src/main/java">
            <property name="enableSubPackages" value="true"/>  
        </javaClientGenerator>  
        <!-- Ҫ���ɵı� tableName�����ݿ��еı�������ͼ�� domainObjectName��ʵ������-->  
        <table tableName="bonus" domainObjectName="Bonus" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false"></table>
    </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.maven2下载关于generator,maven依赖包下载不下来,需要更改为maven3才能下载下来

  • 三、新建maven运行器
<!-- 配置的运行命令-->
mybatis-generator:generate -e

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

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Maven编译代码的相关命令 第一、main目录下的主代码编写完毕后,使用Maven进行编译,在项目根目录下运行命...
    加油小杜阅读 1,272评论 0 2
  • 简介 概述 Maven 是一个项目管理和整合工具 Maven 为开发者提供了一套完整的构建生命周期框架 Maven...
    闽越布衣阅读 4,376评论 6 39
  • Maven使用入门 1. Maven概述 Maven是什么?Maven项目对象模型(POM),可以通过一小段描述信...
    小小韩_小小红阅读 2,589评论 2 28
  • 最近,用在等待上的时间好多,等回复,等电话,等约见,等问候……无休止的等,心烦气燥,真想发飙。 深呼吸 ,调整心态...
    汪凌眉阅读 286评论 1 2
  • 哥们,听说你老婆生了,男孩女孩? 呵呵,男孩! 唉!撅着屁股挣哇,从出生到结婚100来万仅够! 兄弟听说你爸去了,...
    大肚开关阅读 453评论 0 0