• IDEA中使用MyBatis Generator


    1.使用

    如下主要介绍在IDEA 中使用MyBatis Generator 更多想使用请参考官网: http://www.mybatis.org/generator/
    1. 新建一个Maven 项目在POM中添加

     <build>
           <plugins>
                <plugin>
                    <groupId>org.mybatis.generator</groupId>
                    <artifactId>mybatis-generator-maven-plugin</artifactId>
                    <version>1.3.6</version>
                    <configuration>
                      <!--配置文件的位置-->
                        <configurationFile>src/main/resources/generator/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.6</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </build>
    1. 新建generatorConfig.xml 配置内容如下:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE generatorConfiguration
            PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
            "mybatis-generator-config_1_0.dtd">
    
    <generatorConfiguration>
        <!--本地数据库驱动-->
        <classPathEntry location="E:.m2
    epositorymysqlmysql-connector-java6.0.6mysql-connector-java-6.0.6.jar"/>
        <context id="MysqlTables" targetRuntime="MyBatis3">
            <!--去除注释  -->
            <commentGenerator>
                <property name="suppressAllComments" value="true"/>
            </commentGenerator>
    
            <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                            connectionURL="jdbc:mysql://localhost:3306/junli?useUnicode=true&amp;characterEncoding=utf-8&amp;useSSL=false&amp;useJDBCCompliantTimezoneShift=true&amp;useLegacyDatetimeCode=false&amp;serverTimezone=UTC"
                            userId="root"
                            password="123456">
            </jdbcConnection>
    
            <javaTypeResolver>
                <property name="forceBigDecimals" value="false"/>
            </javaTypeResolver>
    
            <!--实体存放位置-->
            <javaModelGenerator targetPackage="com.junly.mybatis.beans"
                                targetProject="G:learnworkspacelearn-mybatissrcmainjava">
                <property name="enableSubPackages" value="true"/>
                <property name="trimStrings" value="true"/>
            </javaModelGenerator>
    
            <!--XML存放位置-->
            <sqlMapGenerator targetPackage="xml" targetProject="G:learnworkspacelearn-mybatissrcmain
    esources">
                <property name="enableSubPackages" value="true"/>
            </sqlMapGenerator>
    
            <!--Mapper存放位置-->
            <javaClientGenerator type="XMLMAPPER" targetPackage="com.junly.mybatis.mapper"
                                 targetProject="G:learnworkspacelearn-mybatis\srcmainjava">
                <property name="enableSubPackages" value="true"/>
            </javaClientGenerator>
    
             <!--需要生成的表-->
            <table schema="junli" tableName="posts" domainObjectName="Posts">
                <property name="useActualColumnNames" value="false"/>
            </table>
            <table schema="junli" tableName="test" domainObjectName="Test">
                <property name="useActualColumnNames" value="false"/>
            </table>
            <table schema="junli" tableName="blog" domainObjectName="Blog">
                <property name="useActualColumnNames" value="false"/>
            </table>
    
            <table schema="junli" tableName="author" domainObjectName="Author">
                <property name="useActualColumnNames" value="false"/>
            </table>
    
        </context>
    </generatorConfiguration>
    1. 生成代码
      在完成以上两步之后。就会在idea中看到:直接点击mybatis-generator:generate就可生成。
      这里写图片描述
  • 相关阅读:
    TCP传输粘包问题
    提取KIndle中每本书的笔记并单独保存
    # 可视化工具资源汇总
    抓取代理IP
    Linux 小工具学习之(1)——Wget十例[翻译]
    [转]关于矩阵的本质
    用2263份证件照图片样本测试how-old.net的人脸识别
    Python生成二维码脚本
    基于git的源代码管理模型——git flow
    使用Graphviz绘图(一)
  • 原文地址:https://www.cnblogs.com/mokingone/p/9109003.html
Copyright © 2020-2023  润新知