• MyBatis逆向工程自动生成配置文件 spring boot工程


      pom.xml中加上mybatis-generator的参数。

    <build>
            <finalName>mybatis-generator</finalName>
            <plugins>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
                <plugin>
                    <groupId>org.mybatis.generator</groupId>
                    <artifactId>mybatis-generator-maven-plugin</artifactId>
                    <version>1.3.2</version>
                    <executions>
                        <execution>
                            <id>Generate Myatis Artifacts</id>
                            <phase>deploy</phase>
                            <goals>
                                <goal>generate</goal>
                            </goals>
                        </execution>
                    </executions>
                    <configuration>
                <!-- <configurationFile>src/main/resources/generator.xml</configurationFile> --> <verbose>true</verbose> <overwrite>true</overwrite> </configuration> <dependencies> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.21</version> </dependency> <dependency> <groupId>org.mybatis.generator</groupId> <artifactId>mybatis-generator-core</artifactId> <version>1.3.2</version> </dependency> <dependency> <groupId>org.mybatis</groupId> <artifactId>mybatis</artifactId> <version>3.4.0</version> </dependency> </dependencies> </plugin> </plugins> </build>

      resources目录下创建generatorConfig.xml文件。    这里的xml也可以是其他的名字,和上面pom文件中的configurationFile对应。

           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="sqlserverTables" targetRuntime="MyBatis3">
            <!-- 生成的pojo,将implements Serializable-->  
            <plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin>  
            <commentGenerator>  
                <!-- 是否去除自动生成的注释 true:是 : false:否 -->
                <property name="suppressAllComments" value="true" />
                <property name="suppressDate" value="true" />
            </commentGenerator>  
      
            <!-- 数据库链接URL、用户名、密码 -->  
            <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                            connectionURL="jdbc:mysql://xxx.xxx.xx.xx:xxxxx/db_msp?useUnicode=true&amp;useJDBCCompliantTimezoneShift=true&amp;useLegacyDatetimeCode=false&amp;serverTimezone=UTC"
                            userId="root"
                            password="xxxyy">
            </jdbcConnection>  
    
            <javaTypeResolver>  
                <property name="forceBigDecimals" value="false" />  
            </javaTypeResolver>  
      
    
            <javaModelGenerator targetPackage="com.raisecom.common.system.model.onuCfg" targetProject="src/main/java">
                <property name="enableSubPackages" value="true"/>  
                <!-- 从数据库返回的值被清理前后的空格  -->
                <property name="trimStrings" value="true" />  
            </javaModelGenerator>
      
            <!--对应的mapper.xml文件  -->
            <sqlMapGenerator targetPackage="resources.mappers.onuCfg" targetProject="src/main">
                <property name="enableSubPackages" value="true"/>  
            </sqlMapGenerator>
    
            <javaClientGenerator type="XMLMAPPER" targetPackage="com.raisecom.common.system.mapper.onuCfg" targetProject="src/main/java">
                <property name="enableSubPackages" value="true"/>
            </javaClientGenerator>
    
            <!-- 列出要生成代码的所有表,这里配置的是不生成Example文件 -->
            <table tableName="cfm_md" domainObjectName="CfmMd"
                   enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
                   enableSelectByExample="false" selectByExampleQueryId="false" >
                <property name="useActualColumnNames" value="false"/>
            </table>
    
            <table tableName="cfm_mep" domainObjectName="CfmMep"
                   enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
                   enableSelectByExample="false" selectByExampleQueryId="false" >
                <property name="useActualColumnNames" value="false"/>
            </table>
    
        </context>
    </generatorConfiguration>  

          

       有几点注意的:

                1.  注意格式,碰到过不是一个空格时,xml会报错

                2.  命令行输入mvn mybatis-generator:generate 或者 鼠标选中工程右侧工具条的maven mybatis插件运行 

                3.  可重复执行,会覆盖已生成的文件 

           4. 可同时生产多个表的文件 表没有主键,只生成insert

  • 相关阅读:
    PHP使用引用变量foreach时,切记其他循环不要使用同一个名字的变量
    PHP 获取给定时间的周日时间或月末时间或每天
    MySQL Load Data InFile 文件内容导入数据库和 Into OutFile导出数据到文件
    直接拿来用!最火的iOS开源项目(一)
    12个有趣的C语言问答
    Flex,Flash,AS3,AIR的关系和区别
    Stage3D大冒险
    c/c++程序中内存区划分
    IOS—— strong weak retain assign 学习
    如何提高你的移动开发中AS3/AIR性能
  • 原文地址:https://www.cnblogs.com/lnlvinso/p/14594866.html
Copyright © 2020-2023  润新知