MyBatisGenerator自动生成

目录

POM.XML

mybatis-generator.xml

启动程序

数据注释/中文注释


MyBatisGenerator自动生成_第1张图片

POM.XML



    4.0.0

    org.example
    mbg
    1.0-SNAPSHOT

    
        8
        8
    

    
        
            org.springframework.boot
            spring-boot-starter
            2.6.4
        
        
            org.springframework.boot
            spring-boot-starter-web
            2.6.4
        
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            2.2.1
        

        
            mysql
            mysql-connector-java
            8.0.15
        

        
            org.mybatis.generator
            mybatis-generator-core
            1.4.0
        
    

mybatis-generator.xml



        

    
    
        
        

            
            
            
        
        
        
        
        
            
        
        
        
            
            
        
        
        
            
        
        
        
            
        
        
        

        

启动程序

public class MyBatisGeneratorDemo {
    public static void main(String[] args) throws Exception {
        new MyBatisGeneratorDemo().running();

    }
    public void running() throws Exception{
        List warnings = new ArrayList();
        boolean overwrite = true;
        InputStream resourceAsStream = this.getClass().getClassLoader().getResourceAsStream("mybatis-generator.xml");
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(resourceAsStream);
        DefaultShellCallback callback = new DefaultShellCallback(overwrite);
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
        myBatisGenerator.generate(null);
    }
}

数据注释/中文注释

public class MybatisCommentGenerator implements CommentGenerator {


@Override
    public void addFieldComment(Field field, IntrospectedTable introspectedTable, IntrospectedColumn introspectedColumn) {
        StringBuilder sb = new StringBuilder();
        field.addJavaDocLine("/**");
        sb.append(" * ");
        sb.append(introspectedColumn.getRemarks());
        field.addJavaDocLine(sb.toString().replace("\n", " "));
        field.addJavaDocLine(" */");
    }

//我只需要在实体类上加注释,所以只实现这个方法
}

你可能感兴趣的:(mysql,postman,java,spring,boot)