SpringBoot整合MyBatis-generator逆向工程

【1】POM文件


    org.mybatis.spring.boot
     mybatis-spring-boot-starter
     2.0.1
 
 
    mysql
       mysql-connector-java
       runtime
   

 
        
            org.springframework.boot
            spring-boot-maven-plugin
        
        
            org.mybatis.generator
            mybatis-generator-maven-plugin
            1.3.2
            
                true
                true
                
                    
                
            
        
    

【2】generator配置文件

generatorConfig.properties

validationQuery=SELECT 1
jdbc_driverClassName=com.mysql.jdbc.Driver
jdbc_url=jdbc:mysql://127.0.0.1:3306/hhprovince?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&useSSL=true
jdbc_username=root
jdbc_password=123456
tableName=user_employee
domainObjectName=SysEmployee

generatorConfig.xml




	
	
	
	
    
          
         
          
        
            
            
            
            
            
        
        
        
        
        
        
            
            
        
        
        
        
            
            
        
        
        
        
            
        
        
        
        
            
        
        
        
        

SpringBoot整合MyBatis-generator逆向工程_第1张图片

关于generator配置文件位置说明

默认情况下,插件会先去src/main/resources下找generatorConfig.xml。如果在pom中插件位置进行了配置文件配置,则会再去指定地方找:


  org.mybatis.generator
        mybatis-generator-maven-plugin
        1.3.2
        
            true
            true
            
                ${basedir}/src/main/resources/generator/generatorConfig.xml
            
        


【3】application.yml配置

server:
  port: 8080

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/hhprovince?serverTimezone=GMT%2B8
    username: root
    password: 123456
#    driver-class-name: com.mysql.jdbc.Driver
    driver-class-name: com.mysql.cj.jdbc.Driver
    type: com.alibaba.druid.pool.DruidDataSource
    initialSize: 5
    minIdle: 5
    maxActive: 20
    maxWait: 60000
    timeBetweenEvictionRunsMillis: 60000
    minEvictableIdleTimeMillis: 300000
    validationQuery: SELECT 1 FROM DUAL
    testWhileIdle: true
    testOnBorrow: true
    testOnReturn: false
    poolPreparedStatements: true
    #   配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
    filters: stat,wall
    maxPoolPreparedStatementPerConnectionSize: 20
    useGlobalDataSourceStat: true
    connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=500
mybatis:
  config-location: classpath:mybatis/mybatis-config.xml
  mapper-locations: classpath*:mybatis/mapper/*.xml

# 下面可以不要
pagehelper:
  helperDialect: mysql
  reasonable: true
  supportMethodsArguments: true
  params: count=countSql


【4】maven命令运行

maven命令:

mybatis-generator:generate -e 

在IntelliJ IDEA中的操作步骤如下:

  • 首先选择Run->Edit Configurations…
  • 然后点击左上角的“+”号,选择Maven
  • 最后在Working directory中填入你项目的根目录,然后在下面的Command line中填入mybatis-generator:generate -e。点击OK即可。

如下图所示:
SpringBoot整合MyBatis-generator逆向工程_第2张图片

你可能感兴趣的:(SpringBoot)