MyBatis: 代码生成器:

一、依赖:



    4.0.0

    cn.edu.tju
    springbootmybatis2029
    1.0.0
    jar

    
        org.springframework.boot
        spring-boot-starter-parent
        2.3.7.RELEASE
        
    

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

                
            
        

        
            org.springframework.boot
            spring-boot-starter-validation
        

        
            org.springframework.boot
            spring-boot-starter-data-redis
        

        
            redis.clients
            jedis
            3.6.0
        




        
            com.google.code.gson
            gson
            2.8.6
        

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

        
            mysql
            mysql-connector-java
            5.1.30
        



        
            com.alibaba
            druid-spring-boot-starter
            1.2.8
        

        

        
            com.github.pagehelper
            pagehelper-spring-boot-starter
            1.2.13
        

        
        
            org.mybatis.generator
            mybatis-generator-core
            1.4.0
        




    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            

        
    



二、配置文件:



    
        
            
        
        


        

        

        

        

三、生成类:

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.exception.XMLParserException;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class Demo {
    public static void main(String[] args) throws Exception {
        List warnings = new ArrayList();
        boolean overwrite = true;
        File configFile = new File("d:\\0000\\01\\conf.xml");
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(configFile);
        DefaultShellCallback callback = new DefaultShellCallback(overwrite);
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
        myBatisGenerator.generate(null);

    }
}

特殊情况:如果表没有主键,则不会生成select等方法,只会生成2个insert方法

你可能感兴趣的:(MyBatis,mybatis)