mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-08 01:28:24 +08:00
commit
2200086791
@ -128,18 +128,6 @@ public class Table {
|
|||||||
|
|
||||||
EntityConfig entityConfig = globalConfig.getEntityConfig();
|
EntityConfig entityConfig = globalConfig.getEntityConfig();
|
||||||
|
|
||||||
//开启 lombok
|
|
||||||
if (entityConfig.isWithLombok()) {
|
|
||||||
//import lombok.AllArgsConstructor;
|
|
||||||
//import lombok.Builder;
|
|
||||||
//import lombok.Data;
|
|
||||||
//import lombok.NoArgsConstructor;
|
|
||||||
imports.add("lombok.AllArgsConstructor");
|
|
||||||
imports.add("lombok.Builder");
|
|
||||||
imports.add("lombok.Data");
|
|
||||||
imports.add("lombok.NoArgsConstructor");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entityConfig.getSupperClass() != null) {
|
if (entityConfig.getSupperClass() != null) {
|
||||||
imports.add(entityConfig.getSupperClass().getName());
|
imports.add(entityConfig.getSupperClass().getName());
|
||||||
}
|
}
|
||||||
@ -277,16 +265,6 @@ public class Table {
|
|||||||
*/
|
*/
|
||||||
public String buildTableAnnotation() {
|
public String buildTableAnnotation() {
|
||||||
StringBuilder tableAnnotation = new StringBuilder();
|
StringBuilder tableAnnotation = new StringBuilder();
|
||||||
if (globalConfig.getEntityConfig().isWithLombok()) {
|
|
||||||
//@Data
|
|
||||||
//@Builder
|
|
||||||
//@NoArgsConstructor
|
|
||||||
//@AllArgsConstructor
|
|
||||||
tableAnnotation.append("@Data\n");
|
|
||||||
tableAnnotation.append("@Builder\n");
|
|
||||||
tableAnnotation.append("@NoArgsConstructor\n");
|
|
||||||
tableAnnotation.append("@AllArgsConstructor\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
tableAnnotation.append("@Table(value = \"").append(name).append("\"");
|
tableAnnotation.append("@Table(value = \"").append(name).append("\"");
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,15 @@
|
|||||||
|
#set(withLombok = entityConfig.isWithLombok())
|
||||||
package #(packageConfig.entityPackage);
|
package #(packageConfig.entityPackage);
|
||||||
|
|
||||||
#for(importClass:table.buildImports())
|
#for(importClass : table.buildImports())
|
||||||
import #(importClass);
|
import #(importClass);
|
||||||
#end
|
#end
|
||||||
|
#if(withLombok)
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
#end
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* #(table.getComment()) 实体类。
|
* #(table.getComment()) 实体类。
|
||||||
@ -10,15 +17,21 @@ import #(importClass);
|
|||||||
* @author #(javadocConfig.getAuthor())
|
* @author #(javadocConfig.getAuthor())
|
||||||
* @since #(javadocConfig.getSince())
|
* @since #(javadocConfig.getSince())
|
||||||
*/
|
*/
|
||||||
|
#if(withLombok)
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
#end
|
||||||
#(table.buildTableAnnotation())
|
#(table.buildTableAnnotation())
|
||||||
public class #(table.buildEntityClassName())#(table.buildExtends())#(table.buildImplements()) {
|
public class #(table.buildEntityClassName())#(table.buildExtends())#(table.buildImplements()) {
|
||||||
#for(column: table.columns)
|
#for(column : table.columns)
|
||||||
|
|
||||||
#(column.buildComment())
|
#(column.buildComment())
|
||||||
#(column.buildAnnotations())private #(column.propertySimpleType) #(column.property);
|
#(column.buildAnnotations())private #(column.propertySimpleType) #(column.property);
|
||||||
#end
|
#end
|
||||||
|
|
||||||
#if(!entityConfig.isWithLombok())
|
#if(!withLombok)
|
||||||
#for(column: table.columns)
|
#for(column: table.columns)
|
||||||
public #(column.propertySimpleType) #(column.getterMethod())() {
|
public #(column.propertySimpleType) #(column.getterMethod())() {
|
||||||
return #(column.property);
|
return #(column.property);
|
||||||
@ -29,5 +42,5 @@ public class #(table.buildEntityClassName())#(table.buildExtends())#(table.build
|
|||||||
}
|
}
|
||||||
|
|
||||||
#end
|
#end
|
||||||
#end
|
#end
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import com.mybatisflex.codegen.Generator;
|
|||||||
import com.mybatisflex.codegen.config.GlobalConfig;
|
import com.mybatisflex.codegen.config.GlobalConfig;
|
||||||
import com.mybatisflex.spring.service.impl.CacheableServiceImpl;
|
import com.mybatisflex.spring.service.impl.CacheableServiceImpl;
|
||||||
import com.zaxxer.hikari.HikariDataSource;
|
import com.zaxxer.hikari.HikariDataSource;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.util.function.UnaryOperator;
|
import java.util.function.UnaryOperator;
|
||||||
|
|
||||||
@ -82,7 +83,7 @@ public class GeneratorTest {
|
|||||||
generator.generate();
|
generator.generate();
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
@Test
|
||||||
public void testCodeGen2() {
|
public void testCodeGen2() {
|
||||||
//配置数据源
|
//配置数据源
|
||||||
HikariDataSource dataSource = new HikariDataSource();
|
HikariDataSource dataSource = new HikariDataSource();
|
||||||
@ -112,8 +113,8 @@ public class GeneratorTest {
|
|||||||
.setGenerateTable("sys_user");
|
.setGenerateTable("sys_user");
|
||||||
|
|
||||||
//设置模板路径
|
//设置模板路径
|
||||||
globalConfig.getTemplateConfig()
|
//globalConfig.getTemplateConfig()
|
||||||
.setEntity("D:\\Documents\\配置文件\\entity.tpl");
|
// .setEntity("D:\\Documents\\配置文件\\entity.tpl");
|
||||||
|
|
||||||
//配置生成 entity
|
//配置生成 entity
|
||||||
globalConfig.enableEntity()
|
globalConfig.enableEntity()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user