jooq插件环境搭建及使用

jooq环境搭建及部署:
1,导入相应jar包并指定生成dao、实体类等的路径及自定义的生成策略

    
      
        org.jooq
        jooq-codegen-maven
        3.8.4
        
          
            none
            
              generate
            
          
        
        
          
            mysql
            mysql-connector-java
            5.1.39
          
        
        
        
          
          
          
            com.mysql.jdbc.Driver
            jdbc:mysql://rm-bp174wmoh9b40f5h4.mysql.rds.aliyuncs.com:3306
            zeustestdbuser
            oSD7mVrAknYYSL5bT4ouP11lyc54f9
          
          
          
          
          
          
          
          
          
          
          
          
          
          
          
            
              org.jooq.util.mysql.MySQLDatabase
              
              
              account
              
              
              
                
                  zeus
                
                
                  imsc
                
               
              
              
              
              
              
              
              
              
              
              
              
              
              
              
            
            
              true
              true
              
              true
              true
            
            
            
              com.xforceplus.hera.domain.jooq
              src/main/java
            
            
              com.xforceplus.hera.domain.dto
              src/main/java
            
            
            
              com.xforceplus.hera.generate.ExtendGeneratorStrategy
            
          
        
      
      
      
      
      
    
  
2,自定义生成策略:
    package com.xforceplus.hera.generate;
    import org.jooq.tools.StringUtils;
    import org.jooq.util.DefaultGeneratorStrategy;
    import org.jooq.util.Definition;
    public class ExtendGeneratorStrategy extends DefaultGeneratorStrategy{
       public static final String PREFIX_UPPER= "T_HERA_";
       public static final String PREFIX_LOWER= "t_hera_";
        public String getJavaClassName(Definition definition, Mode mode) {
            String sourceName = definition.getOutputName();
          sourceName = sourceName.replace(' ', '_').replace('-', '_').replace('.', '_');
          sourceName = sourceName.replace(PREFIX_UPPER, "").replace(PREFIX_LOWER, "");
          if (sourceName.startsWith("t_") || sourceName.startsWith("T_")) {
             sourceName = sourceName.substring(2);
          }
           sourceName = StringUtils.toCamelCase(sourceName);
           if (mode == Mode.POJO) {
               sourceName = sourceName + "Obj";
           }
            if (mode == Mode.RECORD) {
               sourceName = sourceName + "Record";
            }
            else if (mode == Mode.DAO) {
               sourceName = sourceName + "Dao";
            }
            else if (mode == Mode.INTERFACE) {
               sourceName = "I" + sourceName;
            }
           return sourceName;
        }
    }




你可能感兴趣的:(java基础,框架部分,特定功能)