工具类——mybatis-generator自动生成mapper等代码

新建maven项目

1、pom.xml 加入以下代码

<build>
        <plugins>
            <plugin>
                
                <groupId>org.mybatis.generatorgroupId>
                <artifactId>mybatis-generator-maven-pluginartifactId>
                <version>1.3.2version>
                <configuration>
                    
                    <configurationFile>src/main/resources/generatorConfig.xmlconfigurationFile>
                    <verbose>trueverbose>
                    <overwrite>trueoverwrite>
                configuration>
                <executions>
                    <execution>
                        <id>Generate MyBatis Artifactsid>
                        <goals>
                            <goal>generategoal>
                        goals>
                    execution>
                executions>
                <dependencies>
                    <dependency>
                        <groupId>org.mybatis.generatorgroupId>
                        <artifactId>mybatis-generator-coreartifactId>
                        <version>1.3.2version>
                    dependency>
                dependencies>
            plugin>
        plugins>
        <resources>
            <resource>
                <directory>src/main/javadirectory>
                <includes>
                    <include>**/*.xmlinclude>
                includes>
            resource>
        resources>
    build>

2、resources文件夹下新建generatorConfig.xml(名字可随意取)



<generatorConfiguration>

    <classPathEntry
            location="D:/software/maven3.3/repository/mysql/mysql-connector-java/5.1.40/mysql-connector-java-5.1.40.jar" />
    <context id="context1" targetRuntime="MyBatis3">
        
        <commentGenerator>
            <property name="suppressAllComments" value="true" />
            <property name="suppressDate" value="true" />
        commentGenerator>

        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/test" userId="root"
                        password="123456" />

        
        <javaModelGenerator targetPackage="com.zhao.entity"
                            targetProject="src/main/java" />

        
        <sqlMapGenerator targetPackage="com.zhao.mapper"
                         targetProject="src/main/java" />

        
        <javaClientGenerator targetPackage="com.zhao.mapper"
                             targetProject="src/main/java" type="XMLMAPPER" />

         
        <table schema="database_name" tableName="table_name"
               enableCountByExample="false" enableUpdateByExample="false"
               enableDeleteByExample="false" enableSelectByExample="false"
               selectByExampleQueryId="false" />

    context>
generatorConfiguration>

在idea中生成代码的操作

1、下载插件idea-mybatis-generator
工具类——mybatis-generator自动生成mapper等代码_第1张图片
2、在idea右边点击maven,找到新建的maven项目——>Plugins——>mybatis-generator,双击即可生成代码

工具类——mybatis-generator自动生成mapper等代码_第2张图片

在MyEclipse中生成代码的操作

1、点击菜单栏Help–>Install from Site,在Work with输入

mybatis - https://dl.bintray.com/mybatis/mybatis-generator

工具类——mybatis-generator自动生成mapper等代码_第3张图片

2、生成代码(图片为MyEclipse 2017,其他版本只要右键点击那只黑鸟即可)
工具类——mybatis-generator自动生成mapper等代码_第4张图片

你可能感兴趣的:(工具类)