mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
feat: 代码生成,支持 springdoc
This commit is contained in:
parent
2b6b0e3198
commit
4feeb5071d
@ -61,6 +61,25 @@ public class EntityConfig {
|
|||||||
*/
|
*/
|
||||||
private boolean withSwagger;
|
private boolean withSwagger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Swagger 版本
|
||||||
|
*/
|
||||||
|
private SwaggerVersion swaggerVersion;
|
||||||
|
|
||||||
|
public enum SwaggerVersion {
|
||||||
|
FOX("FOX"),
|
||||||
|
DOC("DOC");
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
SwaggerVersion(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 实体类数据源。
|
* 实体类数据源。
|
||||||
*/
|
*/
|
||||||
@ -168,6 +187,23 @@ public class EntityConfig {
|
|||||||
*/
|
*/
|
||||||
public EntityConfig setWithSwagger(boolean withSwagger) {
|
public EntityConfig setWithSwagger(boolean withSwagger) {
|
||||||
this.withSwagger = withSwagger;
|
this.withSwagger = withSwagger;
|
||||||
|
this.swaggerVersion = SwaggerVersion.FOX;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Swagger 版本
|
||||||
|
*/
|
||||||
|
public SwaggerVersion getSwaggerVersion() {
|
||||||
|
return swaggerVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置 Swagger 版本
|
||||||
|
*/
|
||||||
|
public EntityConfig setSwaggerVersion(SwaggerVersion swaggerVersion) {
|
||||||
|
this.swaggerVersion = swaggerVersion;
|
||||||
|
this.withSwagger = swaggerVersion != null;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -898,6 +898,13 @@ public class GlobalConfig {
|
|||||||
return getEntityConfig().isWithSwagger();
|
return getEntityConfig().isWithSwagger();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see EntityConfig#getSwaggerVersion()
|
||||||
|
*/
|
||||||
|
public EntityConfig.SwaggerVersion getSwaggerVersion() {
|
||||||
|
return getEntityConfig().getSwaggerVersion();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see EntityConfig#setWithSwagger(boolean)
|
* @see EntityConfig#setWithSwagger(boolean)
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -70,6 +70,7 @@ public class ControllerGenerator implements IGenerator {
|
|||||||
params.put("controllerConfig", controllerConfig);
|
params.put("controllerConfig", controllerConfig);
|
||||||
params.put("javadocConfig", globalConfig.getJavadocConfig());
|
params.put("javadocConfig", globalConfig.getJavadocConfig());
|
||||||
params.put("withSwagger", globalConfig.isEntityWithSwagger());
|
params.put("withSwagger", globalConfig.isEntityWithSwagger());
|
||||||
|
params.put("swaggerVersion", globalConfig.getSwaggerVersion());
|
||||||
|
|
||||||
globalConfig.getTemplateConfig().getTemplate().generate(params, templatePath, controllerJavaFile);
|
globalConfig.getTemplateConfig().getTemplate().generate(params, templatePath, controllerJavaFile);
|
||||||
|
|
||||||
|
|||||||
@ -23,12 +23,16 @@ import org.springframework.stereotype.Controller;
|
|||||||
#if(controllerConfig.superClass != null)
|
#if(controllerConfig.superClass != null)
|
||||||
import #(controllerConfig.buildSuperClassImport());
|
import #(controllerConfig.buildSuperClassImport());
|
||||||
#end
|
#end
|
||||||
#if(withSwagger)
|
#if(withSwagger && swaggerVersion.getName() == "FOX")
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import io.swagger.annotations.ApiParam;
|
import io.swagger.annotations.ApiParam;
|
||||||
#end
|
#end
|
||||||
|
#if(withSwagger && swaggerVersion.getName() == "DOC")
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import io.swagger.v3.oas.annotations.Operation;
|
||||||
|
import io.swagger.v3.oas.annotations.Parameter;
|
||||||
|
#end
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -43,9 +47,12 @@ import java.util.List;
|
|||||||
#else
|
#else
|
||||||
@Controller
|
@Controller
|
||||||
#end
|
#end
|
||||||
#if(withSwagger)
|
#if(withSwagger && swaggerVersion.getName() == "FOX")
|
||||||
@Api("#(tableComment)接口")
|
@Api("#(tableComment)接口")
|
||||||
#end
|
#end
|
||||||
|
#if(withSwagger && swaggerVersion.getName() == "DOC")
|
||||||
|
@Tag(name = "#(tableComment)接口")
|
||||||
|
#end
|
||||||
@RequestMapping("/#(firstCharToLowerCase(entityClassName))")
|
@RequestMapping("/#(firstCharToLowerCase(entityClassName))")
|
||||||
public class #(table.buildControllerClassName()) #if(controllerConfig.superClass)extends #(controllerConfig.buildSuperClassName()) #end {
|
public class #(table.buildControllerClassName()) #if(controllerConfig.superClass)extends #(controllerConfig.buildSuperClassName()) #end {
|
||||||
|
|
||||||
@ -59,10 +66,13 @@ public class #(table.buildControllerClassName()) #if(controllerConfig.superClass
|
|||||||
* @return {@code true} 添加成功,{@code false} 添加失败
|
* @return {@code true} 添加成功,{@code false} 添加失败
|
||||||
*/
|
*/
|
||||||
@PostMapping("save")
|
@PostMapping("save")
|
||||||
#if(withSwagger)
|
#if(withSwagger && swaggerVersion.getName() == "FOX")
|
||||||
@ApiOperation("保存#(tableComment)")
|
@ApiOperation("保存#(tableComment)")
|
||||||
#end
|
#end
|
||||||
public boolean save(@RequestBody #if(withSwagger)@ApiParam("#(tableComment)") #end #(entityClassName) #(entityVarName)) {
|
#if(withSwagger && swaggerVersion.getName() == "DOC")
|
||||||
|
@Operation(description="保存#(tableComment)")
|
||||||
|
#end
|
||||||
|
public boolean save(@RequestBody #if(withSwagger && swaggerVersion.getName() == "FOX")@ApiParam("#(tableComment)") #end #if(withSwagger && swaggerVersion.getName() == "DOC")@Parameter(description="#(tableComment)")#end #(entityClassName) #(entityVarName)) {
|
||||||
return #(serviceVarName).save(#(entityVarName));
|
return #(serviceVarName).save(#(entityVarName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,10 +83,13 @@ public class #(table.buildControllerClassName()) #if(controllerConfig.superClass
|
|||||||
* @return {@code true} 删除成功,{@code false} 删除失败
|
* @return {@code true} 删除成功,{@code false} 删除失败
|
||||||
*/
|
*/
|
||||||
@DeleteMapping("remove/{id}")
|
@DeleteMapping("remove/{id}")
|
||||||
#if(withSwagger)
|
#if(withSwagger && swaggerVersion.getName() == "FOX")
|
||||||
@ApiOperation("根据主键#(tableComment)")
|
@ApiOperation("根据主键#(tableComment)")
|
||||||
#end
|
#end
|
||||||
public boolean remove(@PathVariable #if(withSwagger)@ApiParam("#(tableComment)主键") #end Serializable id) {
|
#if(withSwagger && swaggerVersion.getName() == "DOC")
|
||||||
|
@Operation(description="根据主键#(tableComment)")
|
||||||
|
#end
|
||||||
|
public boolean remove(@PathVariable #if(withSwagger && swaggerVersion.getName() == "FOX")@ApiParam("#(tableComment)主键") #end #if(withSwagger && swaggerVersion.getName() == "DOC")@Parameter(description="#(tableComment)主键")#end Serializable id) {
|
||||||
return #(serviceVarName).removeById(id);
|
return #(serviceVarName).removeById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,10 +100,13 @@ public class #(table.buildControllerClassName()) #if(controllerConfig.superClass
|
|||||||
* @return {@code true} 更新成功,{@code false} 更新失败
|
* @return {@code true} 更新成功,{@code false} 更新失败
|
||||||
*/
|
*/
|
||||||
@PutMapping("update")
|
@PutMapping("update")
|
||||||
#if(withSwagger)
|
#if(withSwagger && swaggerVersion.getName() == "FOX")
|
||||||
@ApiOperation("根据主键更新#(tableComment)")
|
@ApiOperation("根据主键更新#(tableComment)")
|
||||||
#end
|
#end
|
||||||
public boolean update(@RequestBody #if(withSwagger)@ApiParam("#(tableComment)主键") #end #(entityClassName) #(entityVarName)) {
|
#if(withSwagger && swaggerVersion.getName() == "DOC")
|
||||||
|
@Operation(description="根据主键更新#(tableComment)")
|
||||||
|
#end
|
||||||
|
public boolean update(@RequestBody #if(withSwagger && swaggerVersion.getName() == "FOX")@ApiParam("#(tableComment)主键") #end #if(withSwagger && swaggerVersion.getName() == "DOC")@Parameter(description="#(tableComment)主键")#end#(entityClassName) #(entityVarName)) {
|
||||||
return #(serviceVarName).updateById(#(entityVarName));
|
return #(serviceVarName).updateById(#(entityVarName));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,9 +116,12 @@ public class #(table.buildControllerClassName()) #if(controllerConfig.superClass
|
|||||||
* @return 所有数据
|
* @return 所有数据
|
||||||
*/
|
*/
|
||||||
@GetMapping("list")
|
@GetMapping("list")
|
||||||
#if(withSwagger)
|
#if(withSwagger && swaggerVersion.getName() == "FOX")
|
||||||
@ApiOperation("查询所有#(tableComment)")
|
@ApiOperation("查询所有#(tableComment)")
|
||||||
#end
|
#end
|
||||||
|
#if(withSwagger && swaggerVersion.getName() == "DOC")
|
||||||
|
@Operation(description="查询所有#(tableComment)")
|
||||||
|
#end
|
||||||
public List<#(entityClassName)> list() {
|
public List<#(entityClassName)> list() {
|
||||||
return #(serviceVarName).list();
|
return #(serviceVarName).list();
|
||||||
}
|
}
|
||||||
@ -114,10 +133,13 @@ public class #(table.buildControllerClassName()) #if(controllerConfig.superClass
|
|||||||
* @return #(tableComment)详情
|
* @return #(tableComment)详情
|
||||||
*/
|
*/
|
||||||
@GetMapping("getInfo/{id}")
|
@GetMapping("getInfo/{id}")
|
||||||
#if(withSwagger)
|
#if(withSwagger && swaggerVersion.getName() == "FOX")
|
||||||
@ApiOperation("根据主键获取#(tableComment)")
|
@ApiOperation("根据主键获取#(tableComment)")
|
||||||
#end
|
#end
|
||||||
public #(entityClassName) getInfo(@PathVariable #if(withSwagger)@ApiParam("#(tableComment)主键") #end Serializable id) {
|
#if(withSwagger && swaggerVersion.getName() == "DOC")
|
||||||
|
@Operation(description="根据主键获取#(tableComment)")
|
||||||
|
#end
|
||||||
|
public #(entityClassName) getInfo(@PathVariable #if(withSwagger && swaggerVersion.getName() == "FOX")@ApiParam("#(tableComment)主键") #if(withSwagger && swaggerVersion.getName() == "DOC")@Parameter(description="#(tableComment)主键")#end#end Serializable id) {
|
||||||
return #(serviceVarName).getById(id);
|
return #(serviceVarName).getById(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,10 +150,13 @@ public class #(table.buildControllerClassName()) #if(controllerConfig.superClass
|
|||||||
* @return 分页对象
|
* @return 分页对象
|
||||||
*/
|
*/
|
||||||
@GetMapping("page")
|
@GetMapping("page")
|
||||||
#if(withSwagger)
|
#if(withSwagger && swaggerVersion.getName() == "FOX")
|
||||||
@ApiOperation("分页查询#(tableComment)")
|
@ApiOperation("分页查询#(tableComment)")
|
||||||
#end
|
#end
|
||||||
public Page<#(entityClassName)> page(#if(withSwagger)@ApiParam("分页信息") #end Page<#(entityClassName)> page) {
|
#if(withSwagger && swaggerVersion.getName() == "DOC")
|
||||||
|
@Operation(description="分页查询#(tableComment)")
|
||||||
|
#end
|
||||||
|
public Page<#(entityClassName)> page(#if(withSwagger && swaggerVersion.getName() == "FOX")@ApiParam("分页信息") #end #if(withSwagger && swaggerVersion.getName() == "DOC")@Parameter(description="分页信息")#end Page<#(entityClassName)> page) {
|
||||||
return #(serviceVarName).page(page);
|
return #(serviceVarName).page(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,14 +1,18 @@
|
|||||||
#set(withLombok = entityConfig.isWithLombok())
|
#set(withLombok = entityConfig.isWithLombok())
|
||||||
#set(withSwagger = entityConfig.isWithSwagger())
|
#set(withSwagger = entityConfig.isWithSwagger())
|
||||||
|
#set(swaggerVersion = entityConfig.getSwaggerVersion())
|
||||||
package #(packageConfig.entityPackage);
|
package #(packageConfig.entityPackage);
|
||||||
|
|
||||||
#for(importClass : table.buildImports())
|
#for(importClass : table.buildImports())
|
||||||
import #(importClass);
|
import #(importClass);
|
||||||
#end
|
#end
|
||||||
#if(withSwagger)
|
#if(withSwagger && swaggerVersion.getName() == "FOX")
|
||||||
import io.swagger.annotations.ApiModel;
|
import io.swagger.annotations.ApiModel;
|
||||||
import io.swagger.annotations.ApiModelProperty;
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
#end
|
#end
|
||||||
|
#if(withSwagger && swaggerVersion.getName() == "DOC")
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
#end
|
||||||
#if(withLombok)
|
#if(withLombok)
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
@ -28,13 +32,15 @@ import lombok.NoArgsConstructor;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
#end
|
#end
|
||||||
#if(withSwagger)
|
#if(withSwagger && swaggerVersion.getName() == "FOX")
|
||||||
@ApiModel("#(table.getComment())")
|
@ApiModel("#(table.getComment())")
|
||||||
#end
|
#end
|
||||||
|
#if(withSwagger && swaggerVersion.getName() == "DOC")
|
||||||
|
@Schema(description = "#(table.getComment())")
|
||||||
|
#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)
|
||||||
|
|
||||||
#set(comment = javadocConfig.formatColumnComment(column.comment))
|
#set(comment = javadocConfig.formatColumnComment(column.comment))
|
||||||
#if(isNotBlank(comment))
|
#if(isNotBlank(comment))
|
||||||
/**
|
/**
|
||||||
@ -45,9 +51,12 @@ public class #(table.buildEntityClassName())#(table.buildExtends())#(table.build
|
|||||||
#if(isNotBlank(annotations))
|
#if(isNotBlank(annotations))
|
||||||
#(annotations)
|
#(annotations)
|
||||||
#end
|
#end
|
||||||
#if(withSwagger)
|
#if(withSwagger && swaggerVersion.getName() == "FOX")
|
||||||
@ApiModelProperty("#(column.comment)")
|
@ApiModelProperty("#(column.comment)")
|
||||||
#end
|
#end
|
||||||
|
#if(withSwagger && swaggerVersion.getName() == "DOC")
|
||||||
|
@Schema(description = "#(column.comment)")
|
||||||
|
#end
|
||||||
private #(column.propertySimpleType) #(column.property);
|
private #(column.propertySimpleType) #(column.property);
|
||||||
#end
|
#end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user