SpringBoot2.1 集成 Mybatis Generator 1.3.7

SpringBoot2.1 集成  Mybatis Generator 1.3.7#


 Idea新建项目  如图  选择

  • maven-archetype-webapp:RELEASE

SpringBoot2.1 集成 Mybatis Generator 1.3.7_第1张图片

等待 IDEA 自动创建完成,如下图

SpringBoot2.1 集成 Mybatis Generator 1.3.7_第2张图片

开始集成SpringBoot 和 Mybatis generator 

pom.xml




    4.0.0

    spring-boot
    s_mybatis_generator
    1.0-SNAPSHOT
    war

    s_mybatis_generator Maven Webapp
    
    http://www.example.com

    
        org.springframework.boot
        spring-boot-starter-parent
        2.1.0.BUILD-SNAPSHOT
    


    
        UTF-8
        1.7
        1.7
        ${basedir}/src/main/resources/generatorConfig.xml
        
    

    
        
            junit
            junit
            4.11
            test
        
        
        
            io.netty
            netty-all
            4.1.32.Final
        


        
            org.springframework.boot
            spring-boot-starter-web
        

        
        
            commons-io
            commons-io
            2.6
        


        
            org.springframework.boot
            spring-boot-starter-thymeleaf
        

        
            org.springframework.boot
            spring-boot-starter-test
        


        
            org.springframework.boot
            spring-boot-starter-jdbc
        

        
            mysql
            mysql-connector-java
            5.1.38
        

        
        
            com.squareup.okhttp3
            okhttp
            3.11.0
        


        
        
            com.alibaba
            fastjson
            1.2.49
        


        
            org.mybatis
            mybatis
            3.4.6
        

        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            1.3.2
        


    

    
        s_mybatis_generator

        

            
                org.springframework.boot
                spring-boot-maven-plugin
                
                    true
                
            
            
                org.apache.maven.plugins
                maven-compiler-plugin
                
                    8
                    8
                
            


            
                org.mybatis.generator
                mybatis-generator-maven-plugin
                1.3.7
            

        


        
            
                src/main/java
                
                    **/*.xml
                
            
            
                src/main/resources
            
        

    

配置 application.properties

server.port=9999
logging.level.root=INFO
logging.file=./sb.log
logging.file.x=./sb_x.log
spring.http.encoding.charset=UTF-8
server.tomcat.uri-encoding=UTF-8
server.servlet.session.timeout=3600S

spring.datasource.url=jdbc:mysql://127.0.0.1:3306/chat?useSSL=false
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver

spring.mvc.static-path-pattern=/**

spring.jackson.time-zone=GMT+8
spring.jackson.date-format=yyyy-MM-dd HH:mm:ss

spring.thymeleaf.cache=false


mybatis.mapper-locations=classpath:sbmybatis/test/mapper/xml/*.xml
mybatis.type-aliases-package=classpath:sbmybatis.test.mapper

配置 generatorConfig.xml




    
    
    

        

        
        
        
            
        
        
        
        
            
            
            
        

        
        
        

        
            
        

        
        
            
            
        

        
        
            
        


        
            
        

        

        
        

编写  SpringBoot 启动类 

SpringBoot2.1 集成 Mybatis Generator 1.3.7_第3张图片

SpringBoot2.1 集成 Mybatis Generator 1.3.7_第4张图片在IDEA 中配置 SpringBoot 的启动类

 

SpringBoot2.1 集成 Mybatis Generator 1.3.7_第5张图片

执行 Maven 命令 生成自动的 mapper 和 xml 文件

-Dmybatis.generator.overwrite=true mybatis-generator:generate

如下图  ,文件生成成功 

SpringBoot2.1 集成 Mybatis Generator 1.3.7_第6张图片

在本地MYSQL 里创建测试表  

CREATE TABLE `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `create_date` datetime DEFAULT CURRENT_TIMESTAMP,
  `user_name` varchar(32) NOT NULL,
  `user_status` varchar(32) DEFAULT NULL,
  `user_height` int(11) DEFAULT '0',
  `user_wright` int(11) DEFAULT '0',
  `user_gender` int(11) DEFAULT '0',
  `user_body_type` varchar(32) DEFAULT 'Unknown',
  `user_hair_color` varchar(32) DEFAULT 'Unknown',
  `user_location` varchar(256) DEFAULT 'Unknown',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

表创建好之后, 创建测试 Controller

SpringBoot2.1 集成 Mybatis Generator 1.3.7_第7张图片成功启动应用 

 

 

SpringBoot2.1 集成 Mybatis Generator 1.3.7_第8张图片

数据返回, 大功告成!

源码下载地址  

https://download.csdn.net/download/sw69366/11045739

你可能感兴趣的:(Java,SpringBoot)