Java框架-MyBatis三剑客之MyBatis Generator(mybatis-generator MBG插件)详解(上)

生成器设计思路: 连接数据库 -> 获取表结构 -> 生成文件

1 下载与安装

官网文档入口

Java框架-MyBatis三剑客之MyBatis Generator(mybatis-generator MBG插件)详解(上)

最方便的 maven 插件使用方式

Java框架-MyBatis三剑客之MyBatis Generator(mybatis-generator MBG插件)详解(上)

贴至pom 文件

Java框架-MyBatis三剑客之MyBatis Generator(mybatis-generator MBG插件)详解(上)

2 新建配置文件

填充配置信息(官网示例)

Java框架-MyBatis三剑客之MyBatis Generator(mybatis-generator MBG插件)详解(上)

  • 项目实例
<?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="/Volumes/doc/jar/mysql-connector-java-8.0.18.jar" />

    <context id="DB2Tables" targetRuntime="MyBatis3">
        
        <plugin type="org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin" />

        <commentGenerator>
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>

        <jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
                        connectionURL="jdbc:mysql://127.0.0.1:3306/mall?characterEncoding=utf-8"
                        userId="root"
                        password="root">
        </jdbcConnection>

        <javaTypeResolver >
            <property name="forceBigDecimals" value="false" />
        </javaTypeResolver>

        <javaModelGenerator targetPackage="com.javaedge.mall.pojo" targetProject="src/main/java">
            <property name="enableSubPackages" value="true" />
<!--            <property name="trimStrings" value="true" />-->
        </javaModelGenerator>

        <sqlMapGenerator targetPackage="mappers"  targetProject="src/main/resources">
            <property name="enableSubPackages" value="true" />
        </sqlMapGenerator>

        <javaClientGenerator type="XMLMAPPER" targetPackage="com.javaedge.mall.dao"  targetProject="src/main/java">
            <property name="enableSubPackages" value="true" />
        </javaClientGenerator>

        <table tableName="mall_order" domainObjectName="Order" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/>
        <table tableName="mall_order_item" domainObjectName="OrderItem" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/>

    </context>
</generatorConfiguration>


上一篇:全网最详细的Git学习系列之安装各个Git图形客户端(Windows、Linux、Mac系统皆适用ing)(图文详解)


下一篇:Mybatis3.x 遇到的问题整合[持续更新]