导出 项目 所有接口地址

/**
 * 控制器
 * 
 *
 * @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  工具类根据自己项目调整

效果

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Java EasyExcel 是一款基于注解的 Excel 读写库,相比 Apache POI,EasyExcel 更加易用,支持非常丰富的 Excel 内容读写操作,尤其是在处理大数据量时,性能比 POI 更好。下面是使用 EasyExcel 导出 Excel 的简单示例: 1. 添加 EasyExcel 依赖 在 Maven 项目中,添加 EasyExcel 依赖: ```xml <dependency> <groupId>com.alibaba</groupId> <artifactId>easyexcel</artifactId> <version>2.1.6-beta5</version> </dependency> ``` 2. 定义导出对象 定义一个 Java 类作为导出对象,并在类中使用 @ExcelProperty 注解来标识 Excel 表头及内容,例如: ```java public class ExportData { @ExcelProperty(value = "姓名", index = 0) private String name; @ExcelProperty(value = "年龄", index = 1) private Integer age; //省略 getter 和 setter 方法 } ``` 3. 编写导出逻辑 编写导出逻辑,在方法中调用 EasyExcel 的 write 方法,传入文件路径和导出数据列表即可: ```java public void exportExcel(HttpServletResponse response, List<ExportData> dataList) throws IOException { String fileName = "export.xlsx"; response.setContentType("application/vnd.ms-excel"); response.setCharacterEncoding("utf-8"); response.setHeader("Content-disposition", "attachment;filename=" + fileName); EasyExcel.write(response.getOutputStream(), ExportData.class).sheet("Sheet1").doWrite(dataList); } ``` 4. 调用导出接口 在 Controller 中添加导出接口,并调用导出逻辑方法: ```java @GetMapping("/export") public void export(HttpServletResponse response) throws IOException { List<ExportData> dataList = new ArrayList<>(); // 添加数据到 dataList 中 exportService.exportExcel(response, dataList); } ``` 以上示例代码仅供参考,具体实现还需要根据业务需求进行调整。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值