V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
gaobing
V2EX  ›  分享创造

Java - 使用 @RequestExcel 和 @ResponseExcel 注解轻松上传和下载 Excel 文件

  •  
  •   gaobing ·
    gaoice · 2020-11-25 19:39:47 +08:00 · 2500 次点击
    这是一个创建于 1253 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    下载示例,类似于 @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 中央仓库。

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

    欢迎使用和 Star ^_^

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

    7 条回复    2020-11-28 21:00:21 +08:00
    ychost
        1
    ychost  
       2020-11-25 20:48:35 +08:00
    赞!!
    fd7917931e
        2
    fd7917931e  
       2020-11-26 13:58:47 +08:00
    这个不错!
    shuige
        3
    shuige  
       2020-11-26 15:52:24 +08:00
    2.0 哪里下载?
    zsl199512101234
        4
    zsl199512101234  
       2020-11-26 16:20:42 +08:00
    赞,一开始以为啥 Alibaba 的那个 easyexcel 呢
    2han9wen71an
        5
    2han9wen71an  
       2020-11-26 16:26:31 +08:00
    请问只能在 spring 上用吗?我们平常使用的 resteasy 加 guice 来开发能使用吗?
    gaobing
        6
    gaobing  
    OP
       2020-11-26 18:45:55 +08:00
    uselessVisitor
        7
    uselessVisitor  
       2020-11-28 21:00:21 +08:00
    支持
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2279 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 03:56 · PVG 11:56 · LAX 20:56 · JFK 23:56
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.