swagger导出excel文档_提取swagger内容到csv表格,excel可打开

public classJsonToTxtApplication {public static void main(String[] args) throwsIOException {

SpringApplication.run(JsonToTxtApplication.class, args);

FileInputStream in= new FileInputStream("1.txt");

JsonNode jsonNode= newObjectMapper().readTree(in);/*** 取所有数据并存到HashMap中*/String api;

HashMap> hm = new HashMap<>();

JsonNode node= jsonNode.findValue("paths");

Iterator stringIterator =node.fieldNames();while(stringIterator.hasNext()) {

JsonNode tags= node.findValue((api = stringIterator.next())); //api

Iterator methodsname =tags.fieldNames();while(methodsname.hasNext()) {

String method= methodsname.next(); //方法

JsonNode methods =tags.findValue(method);

String name= methods.findValue("tags").get(0).asText();

String description= methods.findValue("description").asText();

Root root= new Root(name, method, api,description); //当前查询到的一个接口数据//放到hashmap里管理

if(hm.containsKey(root.getName())) {

List roots =hm.get(root.getName());

roots.add(root);

hm.put(root.getName(), roots);

}else{

ArrayList roots = new ArrayList<>();

roots.add(root);

hm.put(root.getName(), roots);

}

}

}/*** 获得name的顺序,并按顺序写入csv*/File file= new File("result.csv");

BufferedWriter bufferedWriter= new BufferedWriter(newOutputStreamWriter(new FileOutputStream(file), "GBK")); //excel不能读取utf-8编码的csv文件

Iterator names = jsonNode.findValue("tags").iterator();while(names.hasNext()) {

String name= names.next().findValue("name").asText();

Iterator iterator1 =hm.get(name).iterator();

bufferedWriter.write(name+ ",");

Boolean isFirst= true;while(iterator1.hasNext()) {

//如果是第一行增加name,如果不是填入空白格if (!isFirst) {

bufferedWriter.write(",");

}else{

isFirst= false;

}

Root next=iterator1.next();

bufferedWriter.write(next.getMethod()+ "," +next.getApi()+ "," +next.getDescription());

bufferedWriter.newLine();

}

}

bufferedWriter.close();

//打开生成的csv文件

Runtime.getRuntime().exec("cmd /c start F:/Project/JsonSoup/result.csv");

System.out.println("done");

}}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值