4mybaits Three Musketeers

1mybaits Three Musketeers

Development Generator: Connect to the database-"Get the table structure-"Generate files

2mybatis generator;

2.1 Introduce dependencies

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-maven-plugin</artifactId>
            <version>1.3.7</version>
            <configuration>
                <overwrite>true</overwrite>
            </configuration>
        </plugin>
    </plugins>
</build>

2.2 Create generatorConfig.xml under resource

Corresponding explanation:
Detailed explanation of Mybatis Generator configuration
https://www.imooc.com/article/21444

<?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>
<!--   1 windows下路径, D:\downloads\xxx.jar-->
    <classPathEntry location="/Users/admin/Desktop/mysql-connector-java-5.1.6.jar" />


    <context id="DB2Tables" targetRuntime="MyBatis3">


<!--        不再追加xml内容-->
        <plugin type="org.mybatis.generator.plugins.UnmergeableXmlMappersPlugin" />

<!--        不生成注释-->
        <commentGenerator>
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>

<!--       2 修改链接地址,用户名和密码-->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://127.0.0.1:3306/mall?characterEncoding=utf-8"
                        userId="root"
                        password="123456">
        </jdbcConnection>


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


  <!--       3 实体类位置,-->
        <javaModelGenerator targetPackage="com.imooc.mall.pojo" targetProject="src/main/java">
            <property name="enableSubPackages" value="true" />
<!--            <property name="trimStrings" value="true" />-->
        </javaModelGenerator>

  <!--       4 mapper位置,-->
        <sqlMapGenerator targetPackage="mappers"  targetProject="src/main/resources">
            <property name="enableSubPackages" value="true" />
        </sqlMapGenerator>

 <!--       5 dao位置,-->
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.imooc.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"/>-->
<!--        <table tableName="mall_user" domainObjectName="User" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/>-->
<!--        <table tableName="mall_category" domainObjectName="Category" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/>-->
<!--        <table tableName="mall_product" domainObjectName="Product" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false">-->
<!--            <columnOverride column="detail" jdbcType="VARCHAR" />-->
<!--            <columnOverride column="sub_images" jdbcType="VARCHAR" />-->
<!--        </table>-->
        <table tableName="mall_shipping" domainObjectName="Shipping" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/>


    </context>
</generatorConfiguration>

Note:
1. There are many notes on the method.
Insert picture description here
Solution:

<!--        不生成注释-->
        <commentGenerator>
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>

2 Generate one more orderExample class
Solution:
Add configuration
enableCountByExample="false" enableDeleteByExample="false"

<table tableName="mall_shipping" domainObjectName="Shipping" enableCountByExample="false" enableDeleteByExample="false" enableSelectByExample="false" enableUpdateByExample="false"/>

Insert picture description here

2.3 Operation:

Insert picture description here

3free-mybatis-plugin

mybatis-plugin. Charges. The installation will report an error, it is not recommended to install
free-mybatis-plugin. Free

3.1 Install plugin

Insert picture description here
Insert picture description here

4mybatis-pagehelper

https://github.com/pagehelper/Mybatis-PageHelper

Guess you like

Origin blog.csdn.net/Insist___/article/details/109100832