导出 项目 所有接口地址

/**
 * 控制器
 * 
 *
 * @author 
 */
@RestController
@AllArgsConstructor
@RequestMapping("/url")
@Api(value = "", tags = "")
public class URLAllController {

    @Autowired
    private WebApplicationContext applicationContext;

    @RequestMapping(value = "/getAllURL", method = RequestMethod.POST)
    public void getAllURL(HttpServletResponse response) {
        List<Map<String, String>> resultList = new ArrayList<>();
        List<URL_message_excel> interface_messages = new ArrayList<>();
        RequestMappingHandlerMapping requestMappingHandlerMapping = applicationContext.getBean(RequestMappingHandlerMapping.class);
        // 获取url与类和方法的对应信息
        Map<RequestMappingInfo, HandlerMethod> map = requestMappingHandlerMapping.getHandlerMethods();

        for (Map.Entry<RequestMappingInfo, HandlerMethod> mappingInfoHandlerMethodEntry : map.entrySet()) {
            Map<String, String> resultMap = new LinkedHashMap<>();

            RequestMappingInfo requestMappingInfo = mappingInfoHandlerMethodEntry.getKey();
            HandlerMethod handlerMethod = mappingInfoHandlerMethodEntry.getValue();

            resultMap.put("className", handlerMethod.getMethod().getDeclaringClass().getName()); // 类名
            Annotation[] parentAnnotations = handlerMethod.getBeanType().getAnnotations();
            for (Annotation annotation : parentAnnotations) {
                if (annotation instanceof Api) {
                    Api api = (Api) annotation;
                    resultMap.put("classDesc", api.value());
                } else if (annotation instanceof RequestMapping) {
                    RequestMapping requestMapping = (RequestMapping) annotation;
                    if (null != requestMapping.value() && requestMapping.value().length > 0) {
                        resultMap.put("classURL", requestMapping.value()[0]);//类URL
                    }
                }
            }
            resultMap.put("methodName", handlerMethod.getMethod().getName()); // 方法名
            Annotation[] annotations = handlerMethod.getMethod().getDeclaredAnnotations();
            if (annotations != null) {
                // 处理具体的方法信息
                for (Annotation annotation : annotations) {
                    if (annotation instanceof ApiOperation) {
                        ApiOperation methodDesc = (ApiOperation) annotation;
                        String desc = methodDesc.value();
                        resultMap.put("methodDesc", desc);//接口描述
                    }
                }
            }
            PatternsRequestCondition p = requestMappingInfo.getPatternsCondition();
            for (String url : p.getPatterns()) {
                resultMap.put("methodURL", url);//请求URL
            }
            RequestMethodsRequestCondition methodsCondition = requestMappingInfo.getMethodsCondition();
            for (RequestMethod requestMethod : methodsCondition.getMethods()) {
                resultMap.put("requestType", requestMethod.toString());//请求方式:POST/PUT/GET/DELETE
            }

            if (resultMap.get("className") == null) {
                resultMap.put("className", "");
            }
            if (resultMap.get("classDesc") == null) {
                resultMap.put("classDesc", "");
            }
            if (resultMap.get("classURL") == null) {
                resultMap.put("classURL", "");
            }
            if (resultMap.get("methodName") == null) {
                resultMap.put("methodName", "");
            }
            if (resultMap.get("methodDesc") == null) {
                resultMap.put("methodDesc", "");
            }
            if (resultMap.get("methodURL") == null) {
                resultMap.put("methodURL", "");
            }
            if (resultMap.get("requestType") == null) {
                resultMap.put("requestType", "");
            }
            resultList.add(resultMap);
            resultMap.put("methodDesc",resultMap.get("classDesc")+"-"+resultMap.get("methodDesc"));
            URL_message_excel copy = BeanUtil.copy(resultMap, URL_message_excel.class);
            interface_messages.add(copy);
        }
        ExcelUtil.export(response, "数据" + DateUtil.time(), "数据表", interface_messages, URL_message_excel.class);
    }



}

import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.ContentRowHeight;
import com.alibaba.excel.annotation.write.style.HeadRowHeight;
import lombok.Data;

import java.io.Serializable;

@Data
@ColumnWidth(25)
@HeadRowHeight(20)
@ContentRowHeight(18)
public class URL_message_excel implements Serializable {
    private static final long serialVersionUID = 1L;
    @ExcelProperty("类名")
    private String  className;
    @ExcelProperty("类地址")
    private String  classURL;
    @ExcelProperty("类描述")
    private String  classDesc;
    @ExcelProperty("方法名")
    private String  methodName;
    @ExcelProperty("方法描述")
    private String  methodDesc;
    @ExcelProperty("方法地址")
    private String  methodURL;
    @ExcelProperty("方法类型")
    private String  requestType;

}


ExcelUtil  工具类根据自己项目调整

效果

 

<think>好的,我需要帮助用户了解如何从IntelliJ IDEA导出接口文档到Apifox。根据用户提供的引用内容,我需要整理出步骤并确保正确引用来源。 首先,用户提到了安装Apifox Helper插件,这是第一步。引用[1]说明这个插件是Apifox团队开发的,所以安装步骤应该在IDEA的插件市场里搜索安装。然后,引用[3]提到需要配置Apifox的访问令牌和项目ID,这应该在设置中进行。接下来,生成文档的步骤在引用[2]里有描述,右键点击类或方法,选择生成API文档。用户可能需要填写相关信息并生成。同步到Apifox的部分,引用[2]和引用[3]都涉及,所以步骤里应该包括一键同步。最后,用户提到的问题是关于列表接口回参显示不了注释,引用[4]给出了解决方法,需要添加自定义规则。这部分可能需要作为常见问题处理,或者放在注意事项里。要确保每个步骤对应正确的引用标记,比如安装插件引用[1],配置引用[3],生成文档引用[2],同步引用[2][3],解决问题引用[4]。另外,用户的问题可能还涉及测试接口,但引用中没有提到测试步骤,所以可能不需要包括。需要检查是否有遗漏的步骤,比如是否需要先编写Swagger注解,但根据引用[3]提到导出Swagger注解,可能需要用户已经添加了这些注解。所以步骤可能包括确保项目有Swagger注解,但引用中没有详细说明,可能需要假设用户已经完成这部分。最后,总结步骤,结构清晰,分点列出,每个步骤后面加上对应的引用标记,确保用户能按照步骤操作,并了解每个步骤的来源。同时,相关问题部分需要根据内容生成,比如如何解决注释不显示,配置问题,同步失败处理等。</think>### 如何从IDEA导出接口文档至Apifox 以下是分步操作指南,结合Apifox Helper插件的功能实现接口文档的生成与同步: 1. **安装Apifox Helper插件** - 打开IntelliJ IDEA,进入`File → Settings → Plugins` - 在Marketplace中搜索"Apifox Helper"并安装[^1] - 重启IDE完成插件激活 2. **配置Apifox项目信息** - 打开`File → Settings → Other Settings → Apifox Helper` - 填入Apifox账号的访问令牌(可在Apifox个人设置中获取) - 输入目标项目的ID(位于Apifox项目设置中)[^3] - 保存配置 3. **生成API文档** - 在项目代码中定位包含接口定义的类或方法(需包含Swagger注解) - 右键点击目标元素,选择`Apifox → Generate API Document` - 在弹出窗口中勾选需要生成的接口 - 补充接口描述、参数说明等信息后点击生成[^2] 4. **同步文档至Apifox** - 生成完成后会自动弹出同步窗口 - 检查接口数据结构与注释的对应关系 - 点击`Sync to Apifox`完成一键同步[^2] 5. **验证同步结果** - 登录Apifox网页端进入目标项目 - 检查接口列表是否更新 - 验证请求参数、响应体结构及注释是否完整显示 **注意事项:** - 若列表接口回参注释未显示,需在插件设置中添加自定义解析规则: ```groovy method.return[#response]=groovy: helper.resolveLink(it.doc("response")) [^4] ``` - 确保代码中已正确使用Swagger注解(如`@ApiModelProperty`) - 同步前建议先执行本地接口测试验证数据结构
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值