mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
完善代码生成
This commit is contained in:
@@ -260,15 +260,17 @@ public class Codegen {
|
|||||||
|
|
||||||
|
|
||||||
// 生成controller
|
// 生成controller
|
||||||
TypeSpec controller = TypeSpec.classBuilder(StringUtils.capitalize(moduleName) + "Controller")
|
TypeSpec.Builder controllerBuilder = TypeSpec.classBuilder(StringUtils.capitalize(moduleName) + "Controller")
|
||||||
.addModifiers(Modifier.PUBLIC)
|
.addModifiers(Modifier.PUBLIC)
|
||||||
.addAnnotation(RestController.class)
|
.addAnnotation(RestController.class)
|
||||||
.addAnnotation(AnnotationSpec.builder(RequestMapping.class).addMember("value", "$S", "/" + lModuleName).build())
|
.addAnnotation(AnnotationSpec.builder(RequestMapping.class).addMember("value", "$S", "/" + lModuleName).build())
|
||||||
.addAnnotation(AnnotationSpec.builder(SysLog.class).addMember("module", "$S", StringUtils.defaultIfBlank(moduleCNName, "")).build())
|
.addAnnotation(AnnotationSpec.builder(SysLog.class).addMember("module", "$S", StringUtils.defaultIfBlank(moduleCNName, "")).build())
|
||||||
.addAnnotation(Slf4j.class)
|
.addAnnotation(Slf4j.class);
|
||||||
.addAnnotation(orgMode ? OrgScope.class : Slf4j.class)
|
|
||||||
|
|
||||||
.addField(FieldSpec.builder(ClassName.get(servicePackage, service.name), "service", Modifier.PRIVATE).addAnnotation(Autowired.class).build())
|
if(orgMode) {
|
||||||
|
controllerBuilder.addAnnotation(OrgScope.class);
|
||||||
|
}
|
||||||
|
controllerBuilder.addField(FieldSpec.builder(ClassName.get(servicePackage, service.name), "service", Modifier.PRIVATE).addAnnotation(Autowired.class).build())
|
||||||
.addMethod(MethodSpec.methodBuilder("create")
|
.addMethod(MethodSpec.methodBuilder("create")
|
||||||
.addModifiers(Modifier.PUBLIC)
|
.addModifiers(Modifier.PUBLIC)
|
||||||
.returns(ClassName.get(dtoPackage, dto.name))
|
.returns(ClassName.get(dtoPackage, dto.name))
|
||||||
@@ -332,10 +334,11 @@ public class Codegen {
|
|||||||
""", ClassName.get(Page.class), ClassName.get(entityPackage, entity.name), ClassName.get(PageRequest.class), ClassName.get(Sort.class))
|
""", ClassName.get(Page.class), ClassName.get(entityPackage, entity.name), ClassName.get(PageRequest.class), ClassName.get(Sort.class))
|
||||||
.build()
|
.build()
|
||||||
)
|
)
|
||||||
.build();
|
;
|
||||||
|
|
||||||
|
|
||||||
JavaFile.builder(controllerPackage, controller)
|
|
||||||
|
JavaFile.builder(controllerPackage, controllerBuilder.build())
|
||||||
.build()
|
.build()
|
||||||
.writeTo(DIRECTORY);
|
.writeTo(DIRECTORY);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user