做一个简单的Swagger文档案例,图片上传,Excel导入导出

目录

一、swagger

  • 号称世界上最流行的Api框架;
  • RestFul Api文档在线自动生成工具=>Api文档与API定义同步更新
  • 直接运行,可以在线测试API接口;
  • 支持多种语言:(Java,Php…

举个栗子user来实现增删改查以及Excel的导入导出还有图片上传
项目目录
在这里插入图片描述
api文档(项目运行后输入地址:http://localhost:8081/swagger-ui.html)
在这里插入图片描述
嗯废话不多说,免费观看小囖咯技术
地址:https://download.csdn.net/download/qq_45047809/15383358

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
当然,我可以为您提供一个Java实现Excel导入导出的具体案例。 首先,我们需要导入 Apache POI 库来操作Excel文件,然后在代码中导入相应的包: import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.ss.usermodel.WorkbookFactory; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.Font; import org.apache.poi.ss.usermodel.HorizontalAlignment; import org.apache.poi.ss.usermodel.IndexedColors; import org.apache.poi.ss.usermodel.BorderStyle; 然后是具体的实现代码: // 导入Excel文件 public Workbook importExcel(InputStream is) throws Exception { Workbook workbook = WorkbookFactory.create(is); return workbook; } // 导出Excel文件 public void exportExcel(List data, OutputStream os) throws Exception { Workbook workbook = new XSSFWorkbook(); Sheet sheet = workbook.createSheet("Sheet1"); // 设置表头 Row header = sheet.createRow(0); CellStyle headerStyle = workbook.createCellStyle(); headerStyle.setAlignment(HorizontalAlignment.CENTER); Font headerFont = workbook.createFont(); headerFont.setBold(true); headerFont.setColor(IndexedColors.WHITE.getIndex()); headerStyle.setFillForegroundColor(IndexedColors.SEA_GREEN.getIndex()); headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND); headerStyle.setFont(headerFont); String[] headerTitles = {"ID", "名称", "分数"}; for (int i = 0; i < headerTitles.length; i++) { Cell cell = header.createCell(i); cell.setCellValue(headerTitles[i]); cell.setCellStyle(headerStyle); } // 设置表格内容 CellStyle contentStyle = workbook.createCellStyle(); contentStyle.setAlignment(HorizontalAlignment.CENTER); Font contentFont = workbook.createFont(); contentFont.setColor(IndexedColors.AUTOMATIC.getIndex()); contentStyle.setFont(contentFont); int rownum = 1; for (Object obj : data) { Row row = sheet.createRow(rownum++); if (obj instanceof Student) { Student s = (Student) obj; Cell cell0 = row.createCell(0); cell0.setCellValue(s.getId()); cell0.setCellStyle(contentStyle); Cell cell1 = row.createCell(1); cell1.setCellValue(s.getName()); cell1.setCellStyle(contentStyle); Cell cell2 = row.createCell(2); cell2.setCellValue(s.getScore()); cell2.setCellStyle(contentStyle); } } // 调整列宽 sheet.autoSizeColumn(0); sheet.autoSizeColumn(1); sheet.autoSizeColumn(2); // 导出Excel文件 workbook.write(os); workbook.close(); } 这是一个非常简单案例,有关Excel导入导出更多的内容可以查询Apache POI官方文档

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

北街风

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值