springboot整合mybatis,pagehelper,代码生成器

引入相关依赖

引入springboot,mybatis的启动器,pagehelper的启动器,mybatis的代码生成器是采用maven插件的形式,



    
        spring-boot-tutorial
        com.ly
        1.0-SNAPSHOT
    
    4.0.0

    mybatis-demo

    
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            1.3.2
        
        
            mysql
            mysql-connector-java
            runtime
        

        
        
            com.github.pagehelper
            pagehelper-spring-boot-starter
            1.2.5
        
        
        
            com.alibaba
            druid-spring-boot-starter
            1.1.9
        


    

    
        
        
            

                
                    org.mybatis.generator
                    mybatis-generator-maven-plugin
                    1.3.2
                    
                        src/main/resources/generatorConfig.xml
                        true
                        true
                    
                    
                        
                            Generate MyBatis Artifacts
                            
                                generate
                            
                        
                    
                    
                        
                            org.mybatis.generator
                            mybatis-generator-core
                            1.3.2
                        

                        
                            mysql
                            mysql-connector-java
                            5.1.46
                        

                    
                


            
        


    



配置文件

debug: true
spring:
    datasource:
        name: test
        url: jdbc:mysql://127.0.0.1:3306/shop?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true
        username: root
        password: a 
        type: com.alibaba.druid.pool.DruidDataSource
        driverClassName: com.mysql.jdbc.Driver
        filters: stat
        maxActive: 20
        initialSize: 1
        maxWait: 60000
        minIdle: 1
        timeBetweenEvictionRunsMillis: 60000
        minEvictableIdleTimeMillis: 300000
        validationQuery: select 'x'
        testWhileIdle: true
        testOnBorrow: false
        testOnReturn: false
        poolPreparedStatements: true
        maxPoolPreparedStatementPerConnectionSize: 20
        maxOpenPreparedStatements: 20
mybatis:
    mapper-locations: classpath:mapper/*.xml
    type-aliases-package: com.ly.entity  # 注意:对应实体类的路径

#pagehelper分页插件
pagehelper:
    helperDialect: mysql
    reasonable: true
    supportMethodsArguments: true
    params: count=countSql

自动生成代码

generatorConfig.xml文件配置








    
    

    
        
        
        
        
        

        
            
            
            
            
        

        
        

        
        
            
        

        
        
        
        
        
        
        
        

进入到项目根目录
输入

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

springboot整合mybatis,pagehelper,代码生成器_第1张图片
最终目录结构如下
springboot整合mybatis,pagehelper,代码生成器_第2张图片

结果

springboot整合mybatis,pagehelper,代码生成器_第3张图片

项目链接

https://github.com/haozhi-ly/spring-boot-tutorial

你可能感兴趣的:(springboot)