在 Spring Boot 中使用 @RequestExcel
和 @ResponseExcel
注解轻松上传和下载 Excel 文件。
下载示例,类似于 @ResponseBody
:
@RequestMapping("/download")
@ResponseExcel({"name", "book.name", "book.author"})
public List<Character> download() {
return listCharacters();
}
上传示例,类似于 @RequestParam
:
@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
**仓库。
Maven
<dependency>
<groupId>com.gaoice</groupId>
<artifactId>easyexcel-spring-boot-starter</artifactId>
<version>2.1</version>
</dependency>
-
v 2.1,提升
@ResponseExcel
注解优先级,现在可以在@RestController
中使用@ResponseExcel
注解。 -
v 2.0,新增
@RequestExcel
注解。
查看 ExcelUploadController 中的上传示例。
查看 ExcelDownloadController 中的下载示例。
运行 DemoApplication ,在 upload.html 尝试导入功能,访问相应的接口查看效果。