• 开发环境搭建之springboot+tk.mybatis整合使用逆向工程


    一,引入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="Mysql" targetRuntime="MyBatis3Simple" defaultModelType="flat">
            <property name="javaFileEncoding" value="UTF-8"/>
            <plugin type="tk.mybatis.mapper.generator.MapperPlugin">
                <property name="mappers" value="com.example.ordersystem.common.mapper.SchoolBaseMapper"/>
            </plugin>
            <!-- 生成注释配置 -->
            <commentGenerator>
                <!-- 是否取消注释 -->
                <property name="suppressAllComments" value="false"/>
                <!-- 数据库注释支持 -->
                <property name="addRemarkComments" value="false"/>
                <!-- 时间格式设置 -->
                <property name="dateFormat" value="yyyy-MM-dd HH:mm:ss"/>
            </commentGenerator>
    
            <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                            connectionURL="jdbc:mysql://ip地址:3306/order_system?serverTimezone=GMT%2B8"
                            userId="root"
                            password="root">
            </jdbcConnection>
    
            <javaModelGenerator targetPackage="com.example.ordersystem.common.entity" targetProject="src/main/java"/>
    
            <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources"/>
    
            <javaClientGenerator targetPackage="com.example.ordersystem.common.mapper"
                                 targetProject="src/main/java" type="XMLMAPPER"/>
    
            <!--       <table tableName="t%" >
                       <generatedKey column="id" sqlStatement="MySql" identity="true" />
                       <domainObjectRenamingRule searchString="^T" replaceString="" />
                       <columnRenamingRule searchString="^T" replaceString=""/>
                   </table>-->
            <table tableName="order_detail">
                <generatedKey column="detail_id" sqlStatement="MySql" identity="true"/>
                <domainObjectRenamingRule searchString="^T" replaceString=""/>
                <columnRenamingRule searchString="^T" replaceString=""/>
            </table>
            <table tableName="order_master">
                <generatedKey column="order_id" sqlStatement="MySql" identity="true"/>
                <domainObjectRenamingRule searchString="^T" replaceString=""/>
                <columnRenamingRule searchString="^T" replaceString=""/>
            </table>
            <table tableName="product_category">
                <generatedKey column="category_id" sqlStatement="MySql" identity="true"/>
                <domainObjectRenamingRule searchString="^T" replaceString=""/>
                <columnRenamingRule searchString="^T" replaceString=""/>
            </table>
            <table tableName="product_info">
                <generatedKey column="product_id" sqlStatement="MySql" identity="true"/>
                <domainObjectRenamingRule searchString="^T" replaceString=""/>
                <columnRenamingRule searchString="^T" replaceString=""/>
            </table>
        </context>
    </generatorConfiguration>

    这个配置文件中可以去除添加去除创建的T

    在pom文件中引入插件:

    <plugin>
                    <groupId>org.mybatis.generator</groupId>
                    <artifactId>mybatis-generator-maven-plugin</artifactId>
                    <version> 1.36</version>
                    <configuration>
                        <configurationFile>${basedir}/src/main/resources/generator/generatorConfiglocal.xml
                        </configurationFile>
                        <overwrite>true</overwrite>
                        <verbose>true</verbose>
                    </configuration>
                    <dependencies>
                        <dependency>
                            <groupId>mysql</groupId>
                            <artifactId>mysql-connector-java</artifactId>
                            <version>runtime</version>
                        </dependency>
                        <dependency>
                            <groupId>tk.mybatis</groupId>
                            <artifactId>mapper</artifactId>
                            <version>3.4.6</version>
                        </dependency>
                    </dependencies>
                </plugin>

    然后再使用maven上个的插件,就可以直接生成dao,mapper,mapper.xml文件

  • 相关阅读:
    深入理解计算机系统 第七章
    第七周 可执行程序的卸载
    Linux内核设计与实现 第三章
    第六周 进程的描述和进程的创建
    第五周 扒开系统调用的三层皮(下)
    UIWebView和Js交互
    CocoaPods的版本升级
    ios图片添加文字或者水印
    Objective-C 关联
    NSString进行urlencode编码
  • 原文地址:https://www.cnblogs.com/qingmuchuanqi48/p/11607468.html
Copyright © 2020-2023  润新知