使用postman上傳excel文件測試導入excel


今日思語:城市的生活很快,有時學會讓自己慢下來,慢慢來

 

對於做一些文件上傳操作時,一般我們是直接在前端頁面加入類型為file的input標簽,也可以使用postman來進行文件的上傳測試,如下:

postman下載地址:https://www.getpostman.com/downloads/ ,下載完之后進行安裝即可。

demo信息表.xls如下:

此處以解析excel文件為例:

 對應后台實現,此處用easypoi處理,需要引入easypoi相關依賴:

        <!--easypoi-->
        <dependency>
            <groupId>cn.afterturn</groupId>
            <artifactId>easypoi-base</artifactId>
            <version>${easypoi.version}</version>
        </dependency>
        <dependency>
            <groupId>cn.afterturn</groupId>
            <artifactId>easypoi-annotation</artifactId>
            <version>${easypoi.version}</version>
        </dependency>
        <dependency>
            <groupId>cn.afterturn</groupId>
            <artifactId>easypoi-web</artifactId>
            <version>${easypoi.version}</version>
        </dependency>

調用接口實現

@RestController
@RequestMapping("/easypoi")
public class EasyPoiExcelController {

    @PostMapping("/importExcel")
    public List<BrandInfo> importExcel(@RequestParam("file") MultipartFile file) throws Exception {     
        List<BrandInfo> BrandInfos = ExcelImportUtil
                .importExcel(file.getInputStream(), BrandInfo.class, new ImportParams());
        return BrandInfos;
    }
}

 

源碼參照:easypoi實現excel導入


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM