jooq自動生成javaコード【脳なし、史上最も簡単】


環境:eclipse+maven
1.まずmavenプロジェクトを新規作成する
2.そして私の下のコードをpomに貼ります.xmlでは、データベースのユーザー名のパスワードを自分のものに変更します.

	  4.0.0
	
	  com
	  myspringboot
	  0.0.1-SNAPSHOT
	  war
	
	  myspringboot
	  http://maven.apache.org
	  
	  
		UTF-8
		1.8
		
		1.8
		1.8
		
		com.mysql.jdbc.Driver
		jdbc:mysql://localhost:3306
		root
		root
		test
	
	  
	    
	    org.springframework.boot  
	    spring-boot-starter-parent  
	    1.4.1.RELEASE  
	    
	
	  
	  	
            org.springframework.boot
            spring-boot-starter-tomcat
            provided
        
	  	
		    com.jolbox
		    bonecp
		    0.8.0.RELEASE
		
	  	
	    
	      junit
	      junit
	      3.8.1
	      test
	    
	    
	      
	        org.springframework.boot  
	        spring-boot-starter-web  
	    
	    
	    
				org.springframework.boot
				spring-boot-starter
		
		
		
				org.springframework.boot
				spring-boot-starter-test
				test
		
		
		  
		    org.springframework.boot  
		    spring-boot-starter-thymeleaf  
		  
	
		
		
		    com.zaxxer
		    HikariCP
		
		
		
		    org.jooq
		    jooq-codegen
		
	     
	        mysql
	        mysql-connector-java
	    
	     
	        org.springframework.boot
	        spring-boot-devtools
	        true
		
		
			org.springframework.boot
			spring-boot-starter-jdbc
			
				
					
					org.apache.tomcat
					tomcat-jdbc
				
			
		
	
  


  
    
      
		
		    
		    org.jooq
		    jooq-codegen-maven
		    
		    
		        
		            
		                generate
		            
		        
		    
		    
		        
		        
		            com.mysql.jdbc.Driver
		            ${db.url}
		            ${db.username}
		            ${db.password}
		        
		        
		        
		            
		                org.jooq.util.mysql.MySQLDatabase
		                .*
		                ${db.schema}
		                false
		                
                            
                                timestamp2DateConverter
                                java.util.Date
                                com.util.Timestamp2DateConverter
                            
                            
                                sqlDate2DateConverter
                                java.util.Date
                                com.util.SQLDate2DateConverter
                                
                            
                            
                                byte2IntegerConverter
                                java.lang.Integer
                                com.util.Byte2IntegerConverter
                            
                         
                         
                             
                                 timestamp2DateConverter
                                 DATETIME|TIMESTAMP
                             
                             
                                 byte2IntegerConverter
                                 TINYINT
                             
                         
		            
		            
                            true
                            true
                            true
                            true
                            true
                            true
                        
		            
		                sxj.db
		                src/main/java
		            
		        
		    
		
		
		
			
				
				
					org.eclipse.m2e
					lifecycle-mapping
					1.0.0
					
						
							
								
									
										org.jooq
										
											jooq-codegen-maven
										
										
											[3.8.4,)
										
										
											generate
										
									
									
										
									
								
							
						
					
				
			
		
  
 


3.右クリック項目-run as-maven generate-sources
4.完成しました.
備考:3つの種類があります.あなたたちは使えるかもしれません.
Byte2IntegerConverter.java
package com.util;

import org.jooq.Converter;

import java.util.Objects;

public class Byte2IntegerConverter implements Converter {

	private static final long serialVersionUID = 1L;

	@Override
    public Integer from(Byte databaseObject) {
        return Objects.isNull(databaseObject) ? null : databaseObject.intValue();
    }

    @Override
    public Byte to(Integer userObject) {
        return Objects.isNull(userObject) ? null : userObject.byteValue();
    }

    @Override
    public Class fromType() {
        return Byte.class;
    }

    @Override
    public Class toType() {
        return Integer.class;
    }

}

Timestamp2DateConverter.java
package com.util;

import org.jooq.Converter;

import java.sql.Timestamp;
import java.util.Date;
import java.util.Objects;

public class Timestamp2DateConverter implements Converter {

	private static final long serialVersionUID = 1529338732611199027L;

	@Override
    public Date from(Timestamp databaseObject) {
        return Objects.isNull(databaseObject) ? null : new Date(databaseObject.getTime());
    }

    @Override
    public Timestamp to(Date userObject) {
        return Objects.isNull(userObject) ? null : new Timestamp(userObject.getTime());
    }

    @Override
    public Class fromType() {
        return Timestamp.class;
    }

    @Override
    public Class toType() {
        return Date.class;
    }

}

SQLDate2DateConverter.java
package com.util;

import org.jooq.Converter;

import java.util.Date;
import java.util.Objects;

public class SQLDate2DateConverter implements Converter {

    @Override
    public Date from(java.sql.Date databaseObject) {
        return Objects.isNull(databaseObject) ? null : new Date(databaseObject.getTime());
    }

    @Override
    public java.sql.Date to(Date userObject) {
        return Objects.isNull(userObject) ? null : new java.sql.Date(userObject.getTime());
    }

    @Override
    public Class fromType() {
        return java.sql.Date.class;
    }

    @Override
    public Class toType() {
        return Date.class;
    }

}