SpringBoot环境中使用MyBatis代码生成工具

一、Maven配置文件中添加如下依赖

专注于为中小企业提供成都做网站、网站设计服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业都昌免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了上千企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。

<dependency>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-core</artifactId>
            <version>1.3.7</version>
        </dependency>
<plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.4</version>
                <dependencies>
                    <dependency>
                        <groupId>MySQL</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>5.1.38</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <verbose>true</verbose>
                    <overwrite>true</overwrite>
                    <configurationFile>${basedir}/src/main/resources/generatorConfig.xml</configurationFile>
                </configuration>
            </plugin>

二、添加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 >
    <!-- mysql jar 文件位置 -->
    <classPathEntry location="F:/instrument\maven/.m2/repository/mysql/mysql-connector-java/5.1.38/mysql-connector-java-5.1.38.jar" />
    <context id="store" targetRuntime="MyBatis3">
        <commentGenerator>
            <!-- 是否去除自动生成的注释 true:是 : false:否 -->
            <property name="suppressAllComments" value="true" />
            <!-- 是否去除所有自动生成的文件的时间戳,默认为false -->
            <!-- <property name="suppressDate" value="false"/> -->
        </commentGenerator>
        <!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
        <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
                        connectionURL="jdbc:mysql://127.0.0.1:3306/g"
                        userId="root"
                        password="root">
        <!--<jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://112.35.82.91:3360/benevolenceParking"
                        userId="renrenbang"
                        password="05377975333">-->
        </jdbcConnection>
        <!-- targetPackage:包名称(自定义)  targetProject:项目路径(自定义)   -->
        <javaModelGenerator targetPackage="com.zblx.park.po" targetProject="src/main/java">
            <!-- enableSubPackages:是否让schema作为包的后缀 -->
            <property name="enableSubPackages" value="false" />
            <!-- 从数据库返回的值被清理前后的空格  -->
            <property name="trimStrings" value="true" />
        </javaModelGenerator>
        <!-- 配置生成相应的实体Mapper.xml,对于Mapper3.X我们需要把type="XMLMAPPER" -->
        <!-- targetPackage:包名称(自定义)  targetProject:项目路径(自定义)   -->
        <sqlMapGenerator targetPackage="com.zblx.park.mapper" targetProject="src/main/java">
            <property name="enableSubPackages" value="false" />
        </sqlMapGenerator>
        <!-- 配置生成相应的接口类,对应与Mapper.xml中的一系列CRUD方法SQL语句 -->
        <!-- targetPackage:包名称(自定义)  targetProject:项目路径(自定义)   -->
        <javaClientGenerator targetPackage="com.zblx.park.dao" targetProject="src/main/java" type="XMLMAPPER">
            <property name="enableSubPackages" value="false" />
        </javaClientGenerator>
        <!-- 用户表-->
        <!--<table schema="benevolenceParking" tableName="parking" domainObjectName="Parking"
               enableCountByExample="false"
               enableUpdateByExample="false"
               enableDeleteByExample="false"
               enableSelectByExample="false"
               selectByExampleQueryId="false"
        >-->
        <table schema="fruit" tableName="parking" domainObjectName="Parking"
               enableCountByExample="false"
               enableUpdateByExample="false"
               enableDeleteByExample="false"
               enableSelectByExample="false"
               selectByExampleQueryId="false"
        />
        <table schema="fruit" tableName="orders" domainObjectName="Orders"
               enableCountByExample="false"
               enableUpdateByExample="false"
               enableDeleteByExample="false"
               enableSelectByExample="false"
               selectByExampleQueryId="false"
        >
        </table>
        <table schema="fruit" tableName="car" domainObjectName="Car"
               enableCountByExample="false"
               enableUpdateByExample="false"
               enableDeleteByExample="false"
               enableSelectByExample="false"
               selectByExampleQueryId="false"
        >
        </table>
        <table schema="fruit" tableName="carlock" domainObjectName="CarLock"
               enableCountByExample="false"
               enableUpdateByExample="false"
               enableDeleteByExample="false"
               enableSelectByExample="false"
               selectByExampleQueryId="false"
        >
        </table>
    </context>
</generatorConfiguration>

分享题目:SpringBoot环境中使用MyBatis代码生成工具
链接URL:https://www.cdcxhl.com/article26/pcgdjg.html

成都网站建设公司_创新互联,为您提供移动网站建设营销型网站建设云服务器软件开发品牌网站设计网站收录

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

搜索引擎优化