KKB : Lombok 插件的使用、mybatis的自动化

安装lombok



添加依赖包

在bean中使用lombok注解

mybatis的自动化

导入pom 文件 以及 plugin插件

<?xml version="1.0" encoding="UTF-8"?>
<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.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>mybatis3</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-core</artifactId>
            <version>1.3.5</version>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.5</version>
                <configuration>
                    <!--配置⽂件的路径-->

                    <configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
                    <overwrite>true</overwrite>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.mybatis.generator</groupId>
                        <artifactId>mybatis-generator-core</artifactId>
                        <version>1.3.5</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

</project>

上面用到了该配置文件,所以我们创建该文件

<?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>
    <!--数据库驱动jar -->
    <classPathEntry
            location="E:\maven\apache-maven-3.6.3\respository\mysql\mysql-connector-java\5.1.40\mysql-connector-java-5.1.40.jar"
    />
    <context id="MyBatis" targetRuntime="MyBatis3">
        <!--去除注释 -->
        <commentGenerator>
            <property name="suppressAllComments" value="true" />
        </commentGenerator>
        <!--数据库连接 -->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/express?useUnicode=true&amp;characterEncoding=utf-8"
                        userId="root"
                        password="123456">
        </jdbcConnection>
        <!--⽣成实体类 指定包名 以及⽣成的地址 (可以⾃定义地址,但是路径不存在不会⾃动创建
        使⽤Maven⽣成在target⽬录下,会⾃动创建) -->
        <javaModelGenerator targetPackage="com.atshiyou.bean"

                            targetProject="E:\IdeaProjects\mybatis3\src\main\java">
            <property name="trimStrings" value="true" />
        </javaModelGenerator>
        <!--⽣成SQLmapper⽂件 -->
        <sqlMapGenerator targetPackage="mapper"

                         targetProject="E:\IdeaProjects\mybatis3\src\main\resources">
        </sqlMapGenerator>
        <!--⽣成Dao⽂件,⽣成接⼝ -->
        <javaClientGenerator type="XMLMAPPER"
                             targetPackage="com.atshiyou.dao"
                             targetProject="E:\IdeaProjects\mybatis3\src\main\java">
        </javaClientGenerator>
        <table tableName="student" enableCountByExample="false"
               enableUpdateByExample="false" enableDeleteByExample="false"
               enableSelectByExample="false" selectByExampleQueryId="false">
        </table>
        <table tableName="grade" enableCountByExample="false"
               enableUpdateByExample="false" enableDeleteByExample="false"
               enableSelectByExample="false" selectByExampleQueryId="false">
        </table>
        <table tableName="role" enableCountByExample="false"
               enableUpdateByExample="false" enableDeleteByExample="false"
               enableSelectByExample="false" selectByExampleQueryId="false">
        </table>
    </context>
</generatorConfiguration>

需要配置

数据库驱动jar的位置:在自己电脑上的目录位置
数据库连接:指定电脑上的数据库
⽣成实体类:指定生成的路径
生成SQLmapper⽂件:指定生成的路径
⽣成Dao⽂件,⽣成接⼝ :指定生成的路径 
指定需要生成的表

点击

代码均自动生成

猜你喜欢

转载自blog.csdn.net/awodwde/article/details/113105944
今日推荐