Generator自动化生成dao以及mapper相应的代码

目录结构

Generator自动化生成dao以及mapper相应的代码_第1张图片

以及添加完相应的依赖在maven工程中出现相应的Plugins双击就可以运行

Generator自动化生成dao以及mapper相应的代码_第2张图片

添加依赖


<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0modelVersion>
    <parent>
        <groupId>org.springframework.bootgroupId>
        <artifactId>spring-boot-starter-parentartifactId>
        <version>2.6.4version>
        <relativePath/> 
    parent>
    <groupId>com.xudagroupId>
    <artifactId>003-springboot-mybatisartifactId>
    <version>1.0.0version>
    <name>003-springboot-mybatisname>
    <description>Demo project for Spring Bootdescription>
    <properties>
        <java.version>1.8java.version>

    properties>
    <dependencies>
        
        <dependency>
            <groupId>mysqlgroupId>
            <artifactId>mysql-connector-javaartifactId>
            <version>5.1.48version>
        dependency>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-thymeleafartifactId>
        dependency>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-webartifactId>
        dependency>
        <dependency>
            
            <groupId>org.mybatis.spring.bootgroupId>
            <artifactId>mybatis-spring-boot-starterartifactId>
            <version>2.2.2version>
        dependency>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-data-redisartifactId>
        dependency>
        <dependency>
            <groupId>org.springframework.bootgroupId>
            <artifactId>spring-boot-starter-testartifactId>
            <scope>testscope>
        dependency>
    dependencies>

    <build>
        
        <resources>
            <resource>
                <directory>src/main/javadirectory>
                <includes>
                    <include>**/*.xmlinclude>
                includes>
            resource>
        resources>
        <plugins>
            

            <plugin>
               <groupId>org.mybatis.generatorgroupId>
                <artifactId>mybatis-generator-maven-pluginartifactId>
                <version>1.3.6version>
                <configuration>
                    
                    <configurationFile>GeneratorMapper.xmlconfigurationFile>
                    <verbose>trueverbose>
                    <overwrite>trueoverwrite>
                configuration>
            plugin>


            <plugin>
                <groupId>org.springframework.bootgroupId>
                <artifactId>spring-boot-maven-pluginartifactId>
            plugin>
        plugins>
    build>

project>

对应的GeneratorMapper.xml下面的table一个表对应一个table



<generatorConfiguration>

    
    <classPathEntry location="D:\app2\mysql-connector-java-5.1.48.jar"/>


    
    <context id="tables" targetRuntime="MyBatis3">
        
        <commentGenerator>
            <property name="suppressAllComments" value="true"/>
        commentGenerator>


        
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/ssmbuild"
                        userId="root"
                        password="">
        jdbcConnection>
        
        <javaModelGenerator targetPackage="com.xuda.model"
                            targetProject="src/main/java">
            <property name="enableSubPackages" value="false"/>
            <property name="trimStrings" value="false"/>
        javaModelGenerator>

        
        <sqlMapGenerator targetPackage="com.xuda.mapper"
                         targetProject="src/main/java">
            <property name="enableSubPackages" value="false"/>
        sqlMapGenerator>

        
        <javaClientGenerator type="XMLMAPPER"
                             targetPackage="com.xuda.mapper" targetProject="src/main/java">
            <property name="enableSubPackages" value="false"/>
        javaClientGenerator>

        
        <table tableName="books" domainObjectName="Books"
               enableCountByExample="false"
               enableUpdateByExample="false"
               enableDeleteByExample="false"
               enableSelectByExample="false"
               selectByExampleQueryId="false"/>
    context>
generatorConfiguration>

你可能感兴趣的:(技术,mybatis)