mybatis逆向工程

一、mybatis 逆向工程简介

    逆向工程简单来说就是传统写代码一般先写对应数据库里面的实体类、数据库接口类、实现类(即xml配置文件)。然而逆向工程是先通过数据库系统自动为你生成这些文件。

二、实现步骤

1、首先创建一个springboot项目
2、在springboot中配置好数据库
3、springboot整合mybatis
yaml配置文件

server:
  port: 8899
  servlet:
    context-path: /

spring:
  datasource: #数据库
    driver-class-name: com.mysql.cj.jdbc.Driver
    type: com.alibaba.druid.pool.DruidDataSource
    url: jdbc:mysql://localhost:3306/leave1?useUnicode=true&characterEncoding=utf8&nullCatalogMeansCurrent=true&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC
    username: root
    password: 1127
  web: #静态资源
    resources:
      static-locations: classpath:/static/,classpath:/templates/
  devtools: #热部署
    livereload:
      enabled: true
  jackson: #时间
    date-format: yyyy-MM-dd HH:mm:ss
    time-zone: GMT+8
  activiti:
    #1 true 没有时候创建,有呢进行更新
    database-schema-update: false
    db-history-used: true
    history-level: full
    check-process-definitions: false

mybatis:
  type-aliases-package: com.chun.model
  mapper-locations: classpath:com/chu/dao/*.xml
  configuration:
    map-underscore-to-camel-case: true

4、利用maven导入mybatis逆向工程相关依赖

<!--逆向工程-->
        <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.2</version>
                  <configuration>
                      <configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
                      <verbose>true</verbose>
                      <overwrite>true</overwrite>
                  </configuration>
              </plugin>

5.创建generatorConfig.xml文件
在这里插入图片描述
在这里插入图片描述
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>
    <!--  <properties resource="mybatis.properties" />
         -->
    <classPathEntry location="E:\07-maven-resp\mysql\mysql-connector-java\8.0.22\mysql-connector-java-8.0.22.jar" />
    <context id="msqlTables" targetRuntime="MyBatis3">
        <plugin type="org.mybatis.generator.plugins.SerializablePlugin"></plugin>
        <jdbcConnection connectionURL="jdbc:mysql://localhost:3306/leave?serverTimezone=GMT%2B8"
                        driverClass="com.mysql.cj.jdbc.Driver" password="1127" userId="root" >
            <property name="nullCatalogMeansCurrent" value="true"/>
        </jdbcConnection>
        <javaTypeResolver>
            <property name="forceBigDecimals" value="false" />
        </javaTypeResolver>
        <javaModelGenerator targetPackage="com.chun.model" targetProject="D:\桌面\leave\src\main\java">
            <property name="enableSubPackages" value="true"/>
            <!-- 从数据库返回的值被清理前后的空格  -->
            <property name="trimStrings" value="true" />
        </javaModelGenerator>
        <sqlMapGenerator targetPackage="com.chun.dao" targetProject="D:\桌面\leave\src\main\resources">
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.chun.dao" targetProject="D:\桌面\leave\src\main\java">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>
        <!--数据库表-->
        <table tableName="user" domainObjectName="User"
               enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
               enableSelectByExample="false" selectByExampleQueryId="false" >
            <property name="useActualColumnNames" value="false"/>
        </table>
       <table tableName="dept_info" domainObjectName="DeptInfo"
           enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
              enableSelectByExample="false" selectByExampleQueryId="false" >
           <property name="useActualColumnNames" value="false"/>
       </table>
       <table tableName="leave_info" domainObjectName="LeaveInfo"
               enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
              enableSelectByExample="false" selectByExampleQueryId="false" >
            <property name="useActualColumnNames" value="false"/>
       </table>
       <table tableName="role_info" domainObjectName="RoleInfo"
               enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false"
              enableSelectByExample="false" selectByExampleQueryId="false" >
           <property name="useActualColumnNames" value="false"/>
       </table>
    </context>
</generatorConfiguration>

在这里插入图片描述
在这里插入图片描述
5、添加maven配置
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
6、运行maven
在这里插入图片描述
生成对应文件
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值