美文网首页
MBG逆向工程

MBG逆向工程

作者: curiosityTao | 来源:发表于2019-04-01 23:30 被阅读0次

    mybatis generator - 逆向工程

    1. pom.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>com.winton</groupId>
        <artifactId>winton-MBG</artifactId>
        <version>1.0-SNAPSHOT</version>
    
        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <targetJavaProject>${basedir}/src/main/java</targetJavaProject>
            <targetMapperPackage>com.winton.mapper</targetMapperPackage>
            <targetModelPackage>com.winton.model</targetModelPackage>
            <!--  XML生成路径  -->
            <targetResourcesProject>${basedir}/src/main/resources</targetResourcesProject>
            <targetXMLPackage>mapper</targetXMLPackage>
            <!--  依赖版本  -->
            <mapper.version>3.4.6</mapper.version>
            <mysql.version>5.1.29</mysql.version>
        </properties>
    
    
        <dependencies>
            <dependency>
                <groupId>junit</groupId>
                <artifactId>junit</artifactId>
                <version>3.8.1</version>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>tk.mybatis</groupId>
                <artifactId>mapper</artifactId>
                <version>${mapper.version}</version>
            </dependency>
            <!-- https://mvnrepository.com/artifact/org.mybatis.generator/mybatis-generator-core -->
            <dependency>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-core</artifactId>
                <version>1.3.2</version>
            </dependency>
    
        </dependencies>
    
    
        <build>
            <plugins>
                <plugin>
                    <groupId>org.mybatis.generator</groupId>
                    <artifactId>mybatis-generator-maven-plugin</artifactId>
                    <version>1.3.2</version>
                    <configuration>
                        <configurationFile>${basedir}/src/main/resources/generator/generatorConfig.xml</configurationFile>
                        <overwrite>true</overwrite>
                        <verbose>true</verbose>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>mysql</groupId>
                            <artifactId>mysql-connector-java</artifactId>
                            <version>${mysql.version}</version>
                        </dependency>
                        <dependency>
                            <groupId>tk.mybatis</groupId>
                            <artifactId>mapper</artifactId>
                            <version>${mapper.version}</version>
                        </dependency>
                    </dependencies>
                </plugin>
            </plugins>
        </build>
    
    
    </project>
    

    2. generatorConfig.xml

    /generator/generatorConfig.xml 注意要与pom文件中<configurationFile>的包一致

    <?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>
        <properties resource="config.properties"/>
    
        <context id="Mysql" targetRuntime="MyBatis3Simple" defaultModelType="flat">
            <property name="beginningDelimiter" value="`"/>
            <property name="endingDelimiter" value="`"/>
    
    
            <!--支持序列化-->
            <plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin>
    
            <commentGenerator>
                <!-- 是否去除自动生成的注释 true:是 : false:否 -->
                <property name="suppressAllComments" value="true"/>
            </commentGenerator>
    
            <!--通用mapper配置-->
          <!--  <plugin type="${mapper.plugin}">
                <property name="mappers" value="${mapper.Mapper}"/>
                <property name="forceAnnotation" value="${mapper.forceAnnotation}"/>
            </plugin>-->
    
            <jdbcConnection driverClass="${jdbc.driverClass}"
                            connectionURL="${jdbc.url}"
                            userId="${jdbc.user}"
                            password="${jdbc.password}">
            </jdbcConnection>
    
            <javaModelGenerator targetPackage="${targetModelPackage}" targetProject="${targetJavaProject}"/>
    
            <sqlMapGenerator targetPackage="${targetXMLPackage}" targetProject="${targetResourcesProject}"/>
    
            <javaClientGenerator targetPackage="${targetMapperPackage}" targetProject="${targetJavaProject}"
                                 type="XMLMAPPER"/>
    
            <table tableName="%">
                <generatedKey column="id" sqlStatement="Mysql" identity="true"/>
            </table>
        </context>
    </generatorConfiguration>
    
    

    3. config.properties

    # 数据库配置
    jdbc.driverClass=com.mysql.jdbc.Driver
    jdbc.url=jdbc:mysql://localhost:3306/pinyougou
    jdbc.user=root
    jdbc.password=root
    
    # 通用Mapper配置
    mapper.plugin=tk.mybatis.mapper.generator.MapperPlugin
    
    mapper.Mapper=tk.mybatis.mapper.common.Mapper
    
    mapper.forceAnnotation=true
    
    

    4. 运行maven命令

    mybatis-generator:generate  //运行就生成完毕
    

    ps: Free Mybatis plugin

    mapper接口和xml切换的插件

    相关文章

      网友评论

          本文标题:MBG逆向工程

          本文链接:https://www.haomeiwen.com/subject/dyeibqtx.html