beetlsql 代码生成示例(lombok、jdk14文本块、junit5)

beetlsql 代码生成示例

  • 测试用例代码
package org.leaf.gencode.tools;

import org.beetl.sql.core.SQLManager;
import org.beetl.sql.ext.gen.GenConfig;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

/***
 * 代码生成
 * @author [email protected]
 * @datetime 2020/6/3 15:44
 * @description
 * pojo代码生成
 */
@SpringBootTest
public class GenHelper {

    @Autowired
    private SQLManager sqlManager;

    private final static String entityTemlate = """
package ${package};

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
${imports}
${implSerializable?"import java.io.Serializable;"}
/**\s
 * ${comment}
 * @author [email protected]
 * gen by beetlsql ${date(),"yyyy-MM-dd"}
 */

@Table(name="${catalog}.${table}")
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Data
public class ${className} ${!isEmpty(ext)?"extends "+ext} ${implSerializable?"implements Serializable"} {
    
    /* alias */
    <%for(attr in attrs){%>
    public static final String ALIAS_${attr.colName} = "${attr.colName}";
    <%}%>
    
    <%for(attr in attrs){
            if(!isEmpty(attr.comment)){%>
    /**
    ${attr.comment}
    */
    <%      }%>
    private ${attr.type} ${attr.name} ;
    <%}%>
}
""";
 
    @Test
    public void genCode() throws Exception {
        GenConfig genConfig = new GenConfig();
        genConfig.setTemplate(entityTemlate);
        genConfig.preferBigDecimal(true);
        sqlManager.genALL("org.leaf.gencode.database.entity",genConfig,null); 
    }
}
  • gradle 开启jdk14 代码块
//junit5
dependencies {
  //项目依赖....

 //spring boot test
    testCompile('org.springframework.boot:spring-boot-starter-test') {
        exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
    }
     //junit 5
    testCompile 'org.junit.jupiter:junit-jupiter:5.5.2'

   //lombok
    implementation 'org.projectlombok:lombok:1.18.8'
    annotationProcessor 'org.projectlombok:lombok:1.18.8'
    testCompileOnly 'org.projectlombok:lombok:1.18.8'
    testAnnotationProcessor 'org.projectlombok:lombok:1.18.8'
}

//jdk14 代码块
tasks.withType(JavaCompile) {
    options.compilerArgs += "--enable-preview"
}
tasks.withType(Test) {
    jvmArgs += "--enable-preview"
}
tasks.withType(JavaExec) {
    jvmArgs += "--enable-preview"
}

你可能感兴趣的:(beetlsql 代码生成示例(lombok、jdk14文本块、junit5))