springboot下的mybatis逆向工程

1.添加jar和plugin

1.1.在pom.xml文件的添加-数据库连接和mybatis依赖:
在这里插入图片描述
1.2添加mybatis逆向工程插件:
在这里插入图片描述

2.配置逆向工程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>

    <properties resource="application.yml"/>
    <!--指定数据库连接的jar包位置,也可以把jar包放在项目中引用,需要注意版本兼容问题-->
    <classPathEntry location="D:/freemarker/maven/apache-maven-3.6.1/repository/mysql/mysql-connector-java/8.0.17/mysql-connector-java-8.0.17.jar"/>
    <context id="Mysql" targetRuntime="MyBatis3">
        <!-- 注释 -->
        <commentGenerator>
            <!-- 是否生成注释时间戳 -->
            <property name="suppressDate" value="true"/>
            <!-- 是否去除自动生成的注释 true:是 : false:否 -->
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>
        <!-- JDBC连接,
        driverClass:在mysql8中为com.mysql.cj.jdbc.Driver,
        mysql5为com.mysql.jdbc.Driver;
         connectionURL:端口号后面请指定自己的数据库名称,还有需要注意添加时区;
         userId和password为数据库连接的账号,密码;-->
        <jdbcConnection
                driverClass="com.mysql.cj.jdbc.Driver"
                connectionURL="jdbc:mysql://localhost:3306/mybatis?serverTimezone=Asia/Shanghai"
                userId="root"
                password="123456">
        </jdbcConnection>
       	<!-- 下列配置默认为false,用于数据库字段类型和java类型的强转匹配-->
        <!--<javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>-->
        <!-- 生成实体类地址 ,如果不存在实体类的包,会自动创建-->
        <javaModelGenerator targetPackage="com.redis.testredis.entity" targetProject="src/main/java">
            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>
        <!-- 生成mapper xml文件 -->
        <sqlMapGenerator targetPackage="mapper" targetProject="src/main/resources">
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>
        <!-- 生成mapper xml对应的mapper接口文件-->
        <javaClientGenerator targetPackage="com.redis.testredis.mapper" targetProject="src/main/java"
                             type="XMLMAPPER">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>
        <!-- 配置表信息,可以配置多个表 -->
        <table tableName="user" domainObjectName="User" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
            <!--mysql 配置-->
            <generatedKey column="id" sqlStatement="Mysql"/>
            <!--oracle 配置-->
            <!--<generatedKey column="id" sqlStatement="select SEQ_{1}.nextval from dual" identity="false" type="pre"/>-->
        </table>
        
        <table tableName="provider" domainObjectName="Provider" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
            <!--mysql 配置-->
            <generatedKey column="pid" sqlStatement="Mysql"/>
        </table>

        <table tableName="bill" domainObjectName="Bill" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false">
            <!--mysql 配置-->
            <generatedKey column="bid" sqlStatement="Mysql"/>
        </table>
    </context>
</generatorConfiguration>

3.edit configuration 中添加一个新的configuration

依照图片的顺序进行操作:
1.点击edit configuration
在这里插入图片描述
2.点击加号选择 maven
在这里插入图片描述在这里插入图片描述3.指定项目根目录,添加命令参数:mybatis-generator:generate -e,然后保存
在这里插入图片描述4.启动刚才我们添加的maven工程:
在这里插入图片描述

关于generatorConfig.xml中属性的作用请参考:

https://blog.net/isea533/article/details/42102297

第一次写博客,如有错误请指正,欢迎讨论。

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值