From c3f6cd2ba11e4aba9a5ef0f3b770f57167689093 Mon Sep 17 00:00:00 2001 From: guo Date: Tue, 8 Aug 2023 18:20:42 +0800 Subject: [PATCH] =?UTF-8?q?bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/zhgd/config/SwaggerConfig.java | 34 ++++++++++--------- .../PoisonousGasDevCurrentDataController.java | 10 +++--- .../controller/${entityName}Controller.javai | 6 ++-- 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/main/java/com/zhgd/config/SwaggerConfig.java b/src/main/java/com/zhgd/config/SwaggerConfig.java index ea88e1750..47c16aaca 100644 --- a/src/main/java/com/zhgd/config/SwaggerConfig.java +++ b/src/main/java/com/zhgd/config/SwaggerConfig.java @@ -28,11 +28,24 @@ public class SwaggerConfig { // 定义分隔符 private static final String splitor = ";"; + @Bean + public Docket createZwRestApi() { + return new Docket(DocumentationType.SWAGGER_2) + .groupName("政务接口") + .apiInfo(apiInfo("政务管理API", "政务前后端联调api文档", "1.0")) + .select() + //.apis(RequestHandlerSelectors.basePackage("com.zhgd.xmgl")) + .apis(basePackage("com.zhwl.zw")) + .paths(PathSelectors.any()) + //.paths(PathSelectors.regex("/zw.*")) + .build(); + } + @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .groupName("项目接口") - .apiInfo(apiInfo("项目管理API","项目前后端联调api文档","1.0")) + .apiInfo(apiInfo("项目管理API", "项目前后端联调api文档", "1.0")) .select() //.apis(RequestHandlerSelectors.basePackage("com.zhgd.xmgl")) .apis(basePackage("com.zhgd.xmgl")) @@ -43,20 +56,7 @@ public class SwaggerConfig { .build(); } - @Bean - public Docket createZwRestApi() { - return new Docket(DocumentationType.SWAGGER_2) - .groupName("政务接口") - .apiInfo(apiInfo("政务管理API","政务前后端联调api文档","1.0")) - .select() - //.apis(RequestHandlerSelectors.basePackage("com.zhgd.xmgl")) - .apis(basePackage("com.zhwl.zw")) - .paths(PathSelectors.any()) - //.paths(PathSelectors.regex("/zw.*")) - .build(); - } - - private ApiInfo apiInfo(String titleName,String description,String version) { + private ApiInfo apiInfo(String titleName, String description, String version) { return new ApiInfoBuilder() .title(titleName) .description(description) @@ -67,7 +67,8 @@ public class SwaggerConfig { public static Predicate basePackage(final String basePackage) { return input -> declaringClass(input).transform(handlerPackage(basePackage)).or(true); } - private static Function, Boolean> handlerPackage(final String basePackage) { + + private static Function, Boolean> handlerPackage(final String basePackage) { return input -> { // 循环判断匹配 for (String strPackage : basePackage.split(splitor)) { @@ -79,6 +80,7 @@ public class SwaggerConfig { return false; }; } + private static Optional> declaringClass(RequestHandler input) { return Optional.fromNullable(input.declaringClass()); } diff --git a/src/main/java/com/zhgd/xmgl/modules/poisonous/controller/PoisonousGasDevCurrentDataController.java b/src/main/java/com/zhgd/xmgl/modules/poisonous/controller/PoisonousGasDevCurrentDataController.java index 5d55d8008..4d12bb097 100644 --- a/src/main/java/com/zhgd/xmgl/modules/poisonous/controller/PoisonousGasDevCurrentDataController.java +++ b/src/main/java/com/zhgd/xmgl/modules/poisonous/controller/PoisonousGasDevCurrentDataController.java @@ -16,6 +16,7 @@ import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections.MapUtils; import org.jeecgframework.poi.excel.ExcelImportUtil; import org.jeecgframework.poi.excel.def.NormalExcelConstants; import org.jeecgframework.poi.excel.entity.ExportParams; @@ -26,6 +27,7 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartHttpServletRequest; import org.springframework.web.servlet.ModelAndView; +import springfox.documentation.annotations.ApiIgnore; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -33,6 +35,7 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -137,14 +140,13 @@ public class PoisonousGasDevCurrentDataController { /** * 通过id删除 * - * @param id * @return */ @ApiOperation(value = "删除有毒气体-数据信息", notes = "删除有毒气体-数据信息", httpMethod = "POST") + @ApiImplicitParam(name = "id", value = "有毒气体-数据ID", paramType = "body", required = true, dataType = "String") @PostMapping(value = "/delete") - public Result delete(@RequestBody String id) { - JSONObject jsonObject = JSON.parseObject(id, JSONObject.class); - id = String.valueOf(jsonObject.get("id")); + public Result delete(@ApiIgnore @RequestBody HashMap map) { + String id = MapUtils.getString(map, "id"); Result result = new Result(); PoisonousGasDevCurrentData poisonousGasDevCurrentData = poisonousGasDevCurrentDataService.getById(id); if (poisonousGasDevCurrentData == null) { diff --git a/src/main/resources/jeecg/code-template/one/java/${bussiPackage}/${entityPackage}/controller/${entityName}Controller.javai b/src/main/resources/jeecg/code-template/one/java/${bussiPackage}/${entityPackage}/controller/${entityName}Controller.javai index 6cc3385c4..413789fd0 100644 --- a/src/main/resources/jeecg/code-template/one/java/${bussiPackage}/${entityPackage}/controller/${entityName}Controller.javai +++ b/src/main/resources/jeecg/code-template/one/java/${bussiPackage}/${entityPackage}/controller/${entityName}Controller.javai @@ -121,10 +121,10 @@ public class ${entityName}Controller { * @return */ @ApiOperation(value = "删除${tableVo.ftlDescription}信息", notes = "删除${tableVo.ftlDescription}信息" , httpMethod="POST") + @ApiImplicitParam(name = "id", value = "${tableVo.ftlDescription}ID", paramType = "body", required = true, dataType = "String") @PostMapping(value = "/delete") - public Result<${entityName}> delete(@RequestBody String id) { - JSONObject jsonObject = JSON.parseObject(id, JSONObject.class); - id = String.valueOf(jsonObject.get("id")); + public Result<${entityName}> delete(@ApiIgnore @RequestBody HashMap map) { + String id = MapUtils.getString(map, "id"); Result<${entityName}> result = new Result<${entityName}>(); ${entityName} ${entityName?uncap_first} = ${entityName?uncap_first}Service.getById(id); if(${entityName?uncap_first}==null) {