springboot maven mybatis generate插件的使用

2021-01-23 18:14

阅读:429

标签:用户   includes   alt   数据库链接   cto   映射文件   als   false   open   

主要步骤:

  • 首先需要在pom.xml中引入mysql依赖、mybatis启动器然后配置generate插件、配置generateConfig.xml的路径、配置资源(mapper.xml、application.yml等)路径
  • 然后配置generateConfig.xml(放到资源路径下)
  • 运行maven generator命令生成代码

1.pom.xml

技术图片技术图片
dependencies>添加如下依赖


dependency>
    groupId>org.mybatis.spring.bootgroupId>
    artifactId>mybatis-spring-boot-starterartifactId>
    version>2.1.2version>
dependency>

dependency>
    groupId>mysqlgroupId>
    artifactId>mysql-connector-javaartifactId>
    version>8.0.19version>
dependency>build>标签下的plugins>标签添加如下配置



plugin>
    groupId>org.mybatis.generatorgroupId>
    artifactId>mybatis-generator-maven-pluginartifactId>
    version>1.3.7version>
    dependencies>
        dependency>
            groupId>mysqlgroupId>
            artifactId>mysql-connector-javaartifactId>
            version>8.0.19version>
        dependency>
    dependencies>

    configuration>
        configurationFile>${project.basedir}/src/main/resources/generateConfig.xmlconfigurationFile>
        verbose>trueverbose>
        overwrite>trueoverwrite>
    configuration>
plugin>build>标签添加如下配置


resources>
    resource>
        directory>src/main/resourcesdirectory>
        includes>
        include>**/*.xmlinclude>
        include>**/*.ymlinclude>
        includes>
    resource>
resources>
            
View Code

 2.generateConfig.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>
    
    
    
    
    context id="context" targetRuntime="MyBatis3">
       
        
        commentGenerator>
            property name="suppressAllComments" value="true" />
            property name="suppressDate" value="true" />
        commentGenerator>
        
        jdbcConnection driverClass="com.mysql.cj.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/springboot?characterEncoding=utf8&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true"
                        userId="root" password="root">
        jdbcConnection>
        
        javaTypeResolver>
            property name="forceBigDecimals" value="false" />
        javaTypeResolver>
        
        javaModelGenerator targetPackage="com.example.springbootmybatis.pojo"
                            targetProject=".\src\main\java">
            property name="enableSubPackages" value="true" />
            property name="trimStrings" value="true" />
        javaModelGenerator>
        
        sqlMapGenerator targetPackage="mapper"
                         targetProject=".\src\main\resources">
            property name="enableSubPackages" value="true" />

        sqlMapGenerator>
        
        javaClientGenerator type="XMLMAPPER"
                             targetPackage="com.example.springbootmybatis.mapper" targetProject=".\src\main\java">
            property name="enableSubPackages" value="true" />
        javaClientGenerator>
        
        table tableName="users" domainObjectName="">table>

    context>
generatorConfiguration>
View Code

3.运行maven generator命令生成代码

技术图片

 

springboot maven mybatis generate插件的使用

标签:用户   includes   alt   数据库链接   cto   映射文件   als   false   open   

原文地址:https://www.cnblogs.com/activestruggle/p/12881840.html


评论


亲,登录后才可以留言!