• 【使用Mybatis-Generator自动生成Mapper、Model、Mapping相关文件】


    一、添加依赖和插件

    在pom文件中添加依赖

            <dependency>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-core</artifactId>
                <version>1.3.5</version>
            </dependency>

    在pom文件中添加插件

        <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-deploy-plugin</artifactId>
                    <configuration>
                        <skip>true</skip>
                    </configuration>
                </plugin>
    
                <plugin>
                    <groupId>org.mybatis.generator</groupId>
                    <artifactId>mybatis-generator-maven-plugin</artifactId>
                    <version>1.3.2</version>
                    <executions>
                        <execution>
                            <id>Generate MyBatis Files</id>
                            <goals>
                                <goal>generate</goal>
                            </goals>
                            <phase>generate</phase>
                            <configuration>
                                <verbose>true</verbose>
                                <overwrite>true</overwrite>
                            </configuration>
                        </execution>
                    </executions>
    
    
                    <dependencies>
                        <dependency>
                            <groupId>mysql</groupId>
                            <artifactId>mysql-connector-java</artifactId>
                            <version>5.1.38</version>
                        </dependency>
                        <dependency>
                            <groupId>org.mybatis.generator</groupId>
                            <artifactId>mybatis-generator-core</artifactId>
                            <version>1.3.5</version>
                        </dependency>
                        <dependency>
                            <groupId>org.mybatis</groupId>
                            <artifactId>mybatis</artifactId>
                            <version>3.4.2</version>
                        </dependency>
    
                    </dependencies>
    
                </plugin>
            </plugins>
        </build>

    二、添加配置文件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>
    
        <context id="zmm" targetRuntime="MyBatis3">
            <!-- Java文件编码UTF-8 -->
            <property name="javaFileEncoding" value="utf-8" />
            <!-- 配置生成父model属性 -->
            <property name="useToStringFromRoot" value="true"/>
            <!-- 配置插件 -->
            <plugin type="org.mybatis.generator.plugins.SerializablePlugin"/>
            <plugin type="org.mybatis.generator.plugins.ToStringPlugin"/>
            <plugin type="org.mybatis.generator.plugins.RowBoundsPlugin"/>
    
            <!-- 关闭注解信息 -->
            <commentGenerator>
                <property name="suppressAllComments" value="false" />
            </commentGenerator>
            <!-- 驱动类路径,见properties配置 -->
            <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                            connectionURL="jdbc:mysql://数据库IP:数据库端口号/数据库名称?useUnicode=true&amp;allowMultiQueries=true&amp;characterEncoding=UTF8&amp;zeroDateTimeBehavior=convertToNull"
                            userId="root"
                            password="123456">
            </jdbcConnection>
    
            <javaTypeResolver>
                <property name="forceBigDecimals" value="false" />
            </javaTypeResolver>
    
            <javaModelGenerator targetPackage="com.yiji.ifp.domain.mybatis.model.auto"
                                targetProject="src/main/java">
                <property name="enableSubPackages" value="true" />
                <property name="trimStrings" value="true" />
            </javaModelGenerator>
    
            <sqlMapGenerator targetPackage="ifpmybatis.auto"
                             targetProject="src/main/resources">
                <property name="enableSubPackages" value="true" />
            </sqlMapGenerator>
    
            <javaClientGenerator type="XMLMAPPER"
                                 targetPackage="com.yiji.ifp.domain.mybatis.mapper.auto"
                                 targetProject="src/main/java">
                <property name="enableSubPackages" value="true" />
            </javaClientGenerator>
    
            <!-- ==========================定义表========================== -->
            <table tableName="%"/>
    
        </context>
    </generatorConfiguration>

    三、配置完成,双击插件即可执行自动生成

    终身学习者
  • 相关阅读:
    20220531复盘
    20220606复盘
    20220607复盘
    20220601复盘
    20220608复盘
    re模块
    os模块
    openpyxl模块
    list
    vim配置与操作
  • 原文地址:https://www.cnblogs.com/zuixinxian/p/9482611.html
Copyright © 2020-2023  润新知