zoukankan      html  css  js  c++  java
  • springBoot集成MyBatis和Mybatis自动生成代码GeneratorMapper.xml配置

    pom.xml配置


    <!--mysql驱动-->

            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
            </dependency>
    <!--mybatis整合springboot框架的起步依赖-->
    <dependency>
                <groupId>org.mybatis.spring.boot</groupId>
                <artifactId>mybatis-spring-boot-starter</artifactId>
                <version>2.1.4</version>
            </dependency>
    <!--mybatis代码自动生成插件-->
    <plugin>
                    <groupId>org.mybatis.generator</groupId>
                    <artifactId>mybatis-generator-maven-plugin</artifactId>
                    <version>1.3.6</version>
                    <configuration>
                        <!--配置文件的位置 -->
                        <configurationFile>GeneratorMapper.xml</configurationFile>
                        <verbose>true</verbose>
                        <overwrite>true</overwrite>
                    </configuration>
                </plugin>

    在pom.xml文件的同级目录新建文件GeneratorMapper.xml

    <?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>
    
        <!-- 指定连接数据库的JDBC驱动包所在位置,指定到你本机的完整路径 -->
        <classPathEntry location="D:/repository/mysql/mysql-connector-java/8.0.26/mysql-connector-java-8.0.26.jar"/>
    
        <!-- 配置table表信息内容体,targetRuntime指定采用MyBatis3的版本 -->
        <context id="tables" targetRuntime="MyBatis3">
            <!--序列化-->
            <plugin type="org.mybatis.generator.plugins.SerializablePlugin"/>
    
            <!--以下需要插件  -->
    
            <!--
                插入成功后返回ID
               <plugin type="cn.doity.common.generator.plugin.InsertAndReturnKeyPlugin"/>
    
               分页查询功能
               <plugin type="cn.doity.common.generator.plugin.SelectByPagePlugin"/>
    
               生成带有for update后缀的select语句插件
               <plugin type="cn.doity.common.generator.plugin.SelectForUpdatePlugin"/> -->
    
    
            <!-- 抑制生成注释,由于生成的注释都是英文的,可以不让它生成 -->
            <commentGenerator>
                <property name="suppressAllComments" value="true" />
            </commentGenerator>
    
    
            <!-- 配置数据库连接信息 -->
            <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                            connectionURL="jdbc:mysql://127.0.0.1:3306/usertest"
                            userId="root"
                            password="root">
            </jdbcConnection>
    
            <!-- *生成model类,
            targetPackage指定model类的包名,
            targetProject指定生成的model放在eclipse的哪个工程下面-->
            <javaModelGenerator
                    targetPackage="com.example.usertest.model"
                    targetProject="src/main/java">
                <property name="enableSubPackages" value="false" />
                <property name="trimStrings" value="false" />
            </javaModelGenerator>
    
            <!-- *生成MyBatis的Mapper.xml文件,t
            argetPackage指定mapper.xml文件的包名,
            targetProject指定生成的mapper.xml放在eclipse的哪个工程下面 -->
            <sqlMapGenerator
                    targetPackage="com.example.usertest.mapper"
                    targetProject="src/main/java">
                <property name="enableSubPackages" value="false" />
            </sqlMapGenerator>
    
            <!-- *生成MyBatis的Mapper接口类文件,
            targetPackage指定Mapper接口类的包名,
            targetProject指定生成的Mapper接口放在eclipse的哪个工程下面 -->
            <javaClientGenerator type="XMLMAPPER"
                                 targetPackage="com.example.usertest.mapper"
                                 targetProject="src/main/java">
                <property name="enableSubPackages" value="false" />
            </javaClientGenerator>
    
            <!-- 数据库表名及对应的Java模型类名 -->
            <table tableName="user"
                   domainObjectName="User"
                   enableCountByExample="false"
                   enableUpdateByExample="false"
                   enableDeleteByExample="false"
                   enableSelectByExample="false"
                   selectByExampleQueryId="false"/>
            <table tableName="userlogs"
                   domainObjectName="Userlogs"
                   enableCountByExample="false"
                   enableUpdateByExample="false"
                   enableDeleteByExample="false"
                   enableSelectByExample="false"
                   selectByExampleQueryId="false"/>
        </context>
    </generatorConfiguration>

     刷新maven

     双击图中是mybatis-generator:generate

    项目中将自动生成实体类、接口、配置文件

  • 相关阅读:
    详细解释:nginx中Nginx Main Module(主模块)配置及各个参数含义
    windows form (窗体) 之间传值小结
    利用C#转换图片格式,还可转换为ico
    修复IE默认主页——注册表篇
    如何截获数据库操作时来自服务器的错误返回码
    C#将代码中的信息保存为txt或ini文件
    修改IE为默认浏览器
    C#中winform窗体常用设置
    各种数据源的连接字符串的写法
    什么是CS和BS结构,两种结构的区别
  • 原文地址:https://www.cnblogs.com/tongxinyuan/p/15435167.html
Copyright © 2011-2022 走看看