mybatis插件生成实体类带有注释(表中Comment字段)的方法-oracle数据库

因为在工作中需要将生成的entity类带有注释信息,方便开发者查看字段属性,所以查找半天,并通过查看源码发现,其实很简单,代码如下:资源下载地址

pom.xml



    4.0.0
    
        org.springframework.boot
        spring-boot-starter-parent
        2.1.2.RELEASE
         
    
    com.example
    demo
    0.0.1-SNAPSHOT
    demo
    Demo project for mybatis generator

    
        1.8
    

    
        
            org.springframework.boot
            spring-boot-starter
        

        
            mysql
            mysql-connector-java
            runtime
        
        
            org.projectlombok
            lombok
            true
        
    
            com.oracle
            ojdbc6
            11.2.0.3.0
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
        
        
        
            org.mybatis.generator
            mybatis-generator-core
            1.3.7
            test
        
        
            commons-lang
            commons-lang
            2.6
        
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            1.3.2
        
    

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


通过实体类main方法,生成entity、dao、xml:

public static void main(String[] args) throws Exception {
        List warnings = new ArrayList();
        boolean overwrite = true;
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(MyBatisGen.class.getClassLoader().getResourceAsStream("generatorConfig.xml"));
        // 解决IDEA下运行,多个模块路径冲突问题
        String cpath = MyBatisGen.class.getClassLoader().getResource("generatorConfig.xml").toString();
        cpath = cpath.substring(0, cpath.indexOf("target")).replace("file:/", "");
        Context context = config.getContexts().get(0);
        context.getJavaModelGeneratorConfiguration().setTargetProject(cpath+context.getJavaModelGeneratorConfiguration().getTargetProject());
        context.getSqlMapGeneratorConfiguration().setTargetProject(cpath+context.getSqlMapGeneratorConfiguration().getTargetProject());
        context.getJavaClientGeneratorConfiguration().setTargetProject(cpath+context.getJavaClientGeneratorConfiguration().getTargetProject());
        DefaultShellCallback callback = new DefaultShellCallback(overwrite);
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
        myBatisGenerator.generate(null);
    }

 

 

你可能感兴趣的:(mybatis)