spring boot + my batis 역방향 생 성

5962 단어 자바
1. 의존 도 추가
        
        
            org.mybatis.spring.boot
            mybatis-spring-boot-starter
            1.3.2
        
          
        
            org.mybatis.generator
            mybatis-generator-core
            1.3.3
        

2. 사용자 정의 주석 생 성기


import org.mybatis.generator.api.IntrospectedColumn;
import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.dom.java.Field;
import org.mybatis.generator.internal.DefaultCommentGenerator;
import org.mybatis.generator.internal.util.StringUtility;

import java.util.Properties;

/**
 *         
 * Created by macro on 2018/4/26.
 */
public class CommentGenerator extends DefaultCommentGenerator {
    private boolean addRemarkComments = false;

    /**
     *          
     */
    @Override
    public void addConfigurationProperties(Properties properties) {
        super.addConfigurationProperties(properties);
        this.addRemarkComments = StringUtility.isTrue(properties.getProperty("addRemarkComments"));
    }

    /**
     *        
     */
    @Override
    public void addFieldComment(Field field, IntrospectedTable introspectedTable,
                                IntrospectedColumn introspectedColumn) {
        String remarks = introspectedColumn.getRemarks();
        //                   
        if(addRemarkComments&&StringUtility.stringHasValue(remarks)){
            //      
            field.addJavaDocLine("/**");
            //            
            String[] remarkLines = remarks.split(System.getProperty("line.separator"));
            for(String remarkLine:remarkLines){
                field.addJavaDocLine(" * "+remarkLine);
            }
            addJavadocTag(field, false);
            field.addJavaDocLine(" */");
        }
    }
}

2. MBG 를 만 드 는 데 사용 되 는 코드 (동작 을 수행 하 는 코드)
import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

/**
 *     MBG   
 * Created by macro on 2018/4/26.
 */
public class Generator {
    public static void main(String[] args) throws Exception {
        //MBG           
        List warnings = new ArrayList();
        //         ,     
        boolean overwrite = true;
        //      MBG     
        InputStream is = Generator.class.getResourceAsStream("/generatorConfig.xml");
        ConfigurationParser cp = new ConfigurationParser(warnings);
        Configuration config = cp.parseConfiguration(is);
        is.close();

        DefaultShellCallback callback = new DefaultShellCallback(overwrite);
        //   MBG
        MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
        //      
        myBatisGenerator.generate(null);
        //      
        for (String warning : warnings) {
            System.out.println(warning);
        }
    }
}

3. 데이터베이스 연결 프로필 (generator. properties)
jdbc.driverClass=oracle.jdbc.OracleDriver
jdbc.connectionURL=jdbc:oracle:thin:@localhost:3306:orcl
jdbc.userId=root
jdbc.password=root

4. 정책 프로필 생 성




   
    

        
        
        

        
        
        
        

        
            
            
            
            
        

        
        

		
		
			
		


		

        

        
        
        

좋은 웹페이지 즐겨찾기