Idea使用Mybatis Generator

首先我们要明白我们能够使用MyBatis Generator做什么,继而明白怎么做,MyGenerator能够依据我们提供的配置文件生成相响应的dao以及pojo,加速我们的开发, 下面我们来看怎么做:

  1. pom文件中引入MyBatis Generator
    
        BuildEnergy
        
            
            
                org.apache.maven.plugins
                maven-compiler-plugin
                
                    1.7
                    1.7
                
            
            
                org.mybatis.generator
                mybatis-generator-maven-plugin
                1.3.2
                
                    true
                    true
                
            
        
    
  1. 设置具体生成时的一些设定,如存放pojo以及dao的包路径等,主要涉及两个文件generator.properties以及generatorConfig.xml,建议放在resource目录下:

如下是两个文件的内容

generator.properties

jdbc.driverLocation=F:\\jars\\mysql-connector-java-5.1.21.jar
jdbc.driverClass=com.mysql.jdbc.Driver
jdbc.connectionURL=jdbc:mysql:///energy
jdbc.userId=root
jdbc.password=

generatorConfig.xml





    
    

    
    

    

        
        
            
            
        

        
        
        


        
        
            
        


        
        

            
            
            
            
            
            
            
            
        

        
        
            
        

        
        
            
        


        
  1. run maven generator生成代码

此步我们需要配置一个run项,maven目标设定为 mybatis-generator:generate -e
如下图所示:

Idea使用Mybatis Generator_第1张图片
Paste_Image.png

最后run一下得到如下结果:

![Upload Paste_Image.png failed. Please try again.]
可以看到,我们已经得到了我们想要的dao以及pojo,最后不忘测试一把,见下图:

Idea使用Mybatis Generator_第2张图片
Paste_Image.png

你可能感兴趣的:(Idea使用Mybatis Generator)