idea借助mybatis-generator生成后端代码基本增删改查

1、在pom中的下的中导入mybatis-generator插件

            <!--            mybatis 逆向工程    -->
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.6</version>
                <configuration>
                    <!-- Mybatis-Generator 工具配置文件的位置 -->
                    <configurationFile>src/main/resources/mybatis/generatorConfig.xml</configurationFile>
                    <verbose>true</verbose>
                    <overwrite>true</overwrite>
                </configuration>
            </plugin>

2、导入成功后可以在idea右侧看到mybatis-generator
在这里插入图片描述
3、在resources下创建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>

    <classPathEntry
            location="D:\warehouse\mysql\mysql-connector-java\8.0.19\mysql-connector-java-8.0.19.jar"/>
    <context id="mysql" targetRuntime="MyBatis3Simple"
             defaultModelType="flat">

        <property name="beginningDelimiter" value="`"/>
        <property name="endingDelimiter" value="`"/>
        <!-- <plugin type="tk.mybatis.mapper.generator.MapperPlugin"> <property
            name="mappers" value="org.zn.mvcbase.mybatis.CommonsMapper" /> </plugin> -->
        <commentGenerator>
            <property name="suppressAllComments" value="true"/>
            <property name="suppressDate" value="true"/>
        </commentGenerator>

        <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/nfshop?useUnicode=true&amp;characterEncoding=utf-8&amp;serverTimezone=Asia/Shanghai"
                        userId="root" password="123456">
            <!--MySQL 8.x 需要指定服务器的时区-->
            <property name="serverTimezone" value="UTC"/>
            <!--MySQL 不支持 schema 或者 catalog 所以需要添加这个-->
            <!--参考 : http://www.mybatis.org/generator/usage/mysql.html-->
            <property name="nullCatalogMeansCurrent" value="true"/>
            <!-- MySQL8默认启用 SSL ,不关闭会有警告-->
            <property name="useSSL" value="false"/>
        </jdbcConnection>
        <!-- po -->
        <javaModelGenerator
                targetPackage="com.zjj.nfshop.entity"
                targetProject="D:\Project\nfshop\src\main\java"
        />
        <!--E:\project\fas\fas4\fas-haiot-interface\src\main\java-->
        <!--E:\project\fas\fas4\fas-haiot-interface\src\main\resources-->
        <!--D:\CodeSpace\Gitee\区级-区域级消防物联网平台\fas4.0-interface\src\main\java-->
        <!--D:\CodeSpace\Gitee\区级-区域级消防物联网平台\fas4.0-interface\src\main\resources-->
        <!-- mapper -->
        <sqlMapGenerator
                targetPackage="mybatis.mapper"
                targetProject="D:\Project\nfshop\src\main\resources"
        />
        <!-- dao -->
        <javaClientGenerator
                targetPackage="com.zjj.nfshop.mapper"
                targetProject="D:\Project\nfshop\src\main\java"
                type="ANNOTATEDMAPPER"
        />
        <!--生成表数据-->
        <table tableName="cart" schema="fas4"
               enableCountByExample="true" enableUpdateByExample="true"
               enableDeleteByExample="true" enableSelectByExample="true"
               selectByExampleQueryId="true">
            <property name="useActualColumnNames" value="false"/>
        </table>
        <table tableName="administrators" schema="fas4"
               enableCountByExample="true" enableUpdateByExample="true"
               enableDeleteByExample="true" enableSelectByExample="true"
               selectByExampleQueryId="true">
            <property name="useActualColumnNames" value="false"/>
        </table>
        <table tableName="good" schema="fas4"
               enableCountByExample="true" enableUpdateByExample="true"
               enableDeleteByExample="true" enableSelectByExample="true"
               selectByExampleQueryId="true">
            <property name="useActualColumnNames" value="false"/>
        </table>
        <table tableName="orders" schema="fas4"
               enableCountByExample="true" enableUpdateByExample="true"
               enableDeleteByExample="true" enableSelectByExample="true"
               selectByExampleQueryId="true">
            <property name="useActualColumnNames" value="false"/>
        </table>
        <table tableName="users" schema="fas4"
               enableCountByExample="true" enableUpdateByExample="true"
               enableDeleteByExample="true" enableSelectByExample="true"
               selectByExampleQueryId="true">
            <property name="useActualColumnNames" value="false"/>
        </table>
    </context>
</generatorConfiguration>

4、双击运行
在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值