使用 @RequestExcel 和 @ResponseExcel 註解輕鬆上傳和下載 Excel 文件

作成了 Spring Boot Starter 的形式,方便引入使用。java

下載示例,相似於 @ResponseBodygit

@RequestMapping("/download")
@ResponseExcel({"name", "book.name", "book.author"})
public List<Character> download() {
    return listCharacters();
}

上傳示例,相似於 @RequestParamgithub

@RequestMapping("/upload")
@ResponseBody
public List<Character> upload(@RequestExcel(value = "excel", targetClass = Character.class, 
                                            fieldNames = {"name", "book.name", "book.author"}) 
                                List<Character> characters) {
    return characters;
}

已提交至 Maven 中央倉庫。spring

<dependency>
    <groupId>com.gaoice</groupId>
    <artifactId>easyexcel-spring-boot-starter</artifactId>
    <version>2.0</version>
</dependency>

GitHub: https://github.com/gaoice/easyexcel-spring-boot-starterapp

相關文章
相關標籤/搜索