• mybatis逆向工程的构建及其概念


    概念

    正向工程:先创建Java实体类,由框架负责根据实体类生成数据库表。Hibernate是支持正向工程的。

    逆向工程:先创建数据库表,由框架负责根据数据库表,反向生成如下资源:
    Java实体类
    Mapper接口
    Mapper配置文件

    maven的pom.xml文件

    
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0modelVersion>
    
        <groupId>com.powernodegroupId>
        <artifactId>mybatis-012-generator1artifactId>
        <version>1.0-SNAPSHOTversion>
        <dependencies>
            
            <dependency>
                <groupId>org.mybatis.cachesgroupId>
                <artifactId>mybatis-ehcacheartifactId>
                <version>1.2.2version>
            dependency>
            
            <dependency>
                <groupId>org.mybatisgroupId>
                <artifactId>mybatisartifactId>
                <version>3.5.10version>
            dependency>
            <dependency>
                
                <groupId>mysqlgroupId>
                <artifactId>mysql-connector-javaartifactId>
                <version>8.0.30version>
            dependency>
            
            <dependency>
                <groupId>junitgroupId>
                <artifactId>junitartifactId>
                <version>4.13.2version>
                <scope>testscope>
            dependency>
            
            <dependency>
                <groupId>ch.qos.logbackgroupId>
                <artifactId>logback-classicartifactId>
                <version>1.2.11version>
                <scope>testscope>
            dependency>
        dependencies>
        <packaging>jarpackaging>
    
        <properties>
            <maven.compiler.source>17maven.compiler.source>
            <maven.compiler.target>17maven.compiler.target>
            <project.build.sourceEncoding>UTF-8project.build.sourceEncoding>
        properties>
    
        
        
        <build>
            
            <plugins>
                
                <plugin>
                    
                    <groupId>org.mybatis.generatorgroupId>
                    <artifactId>mybatis-generator-maven-pluginartifactId>
                    <version>1.4.1version>
                    
                    <configuration>
                        <overwrite>trueoverwrite>
                    configuration>
                    
                    <dependencies>
                        
                        <dependency>
                            <groupId>mysqlgroupId>
                            <artifactId>mysql-connector-javaartifactId>
                            <version>8.0.30version>
                        dependency>
                    dependencies>
                plugin>
            plugins>
        build>
    
    project>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80

    generatorConfig.xml配置文件

    
    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="DB2Tables" targetRuntime="MyBatis3">
            
            <plugin type="org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin"/>
    
            <commentGenerator>
                
                <property name="suppressDate" value="true"/>
                
                <property name="suppressAllComments" value="true"/>
            commentGenerator>
    
            
            <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
                            connectionURL="jdbc:mysql://localhost:3306/powernode"
                            userId="root"
                            password="123456">
            jdbcConnection>
    
            
            <javaModelGenerator targetPackage="com.powernode.mybatis.pojo" targetProject="src/main/java">
                
                <property name="enableSubPackages" value="true"/>
                
                <property name="trimStrings" value="true"/>
            javaModelGenerator>
    
            
            <sqlMapGenerator targetPackage="com.powernode.mybatis.mapper"
                             targetProject="src/main/resources">
                
                <property name="enableSubPackages" value="true"/>
            sqlMapGenerator>
    
            
            
            <javaClientGenerator
                    type="xmlMapper"
                    targetPackage="com.powernode.mybatis.mapper"
                    targetProject="src/main/java">
                <property name="enableSubPackages" value="true"/>
            javaClientGenerator>
    
            
            <table tableName="t_car" domainObjectName="Car"/>
    
        context>
    generatorConfiguration>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61

    点击这个即可生成pojo,sql映射文件,以及mapper接口

    在这里插入图片描述

  • 相关阅读:
    Vue面试题
    Nginx proxy_pass 详解
    Java泛型
    git 的基本命令行
    anylogic 学习(3)—— 智能体相关操作
    LeetCode HOT 100 —— 11.盛最多水的容器
    1131 Subway Map
    EXCEL——根据单元格值设置不同色阶
    Vue学习:分析hello案例
    甜蜜约会网页制作html
  • 原文地址:https://blog.csdn.net/m0_64803878/article/details/132782203