请问spring boot 框架后台怎么获取前台上传的excel文件,并解析excel文件内容

qq_37641038 2017-07-27 04:08:51
前台html页面上传excel文件按钮:
<form action="give" method="post" enctype="multipart/form-data" th:method="GET">
<input type="file" name="file">
<input type="submit" value="导入excel">
</form>

后台应该怎么写?
...全文
1931 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
howroad 2018-05-25
  • 打赏
  • 举报
回复
有一个框架是POI专门做这个事情
Phil_Jing 2018-05-24
  • 打赏
  • 举报
回复
<form action="give" method="post" enctype="multipart/form-data" th:method="POST">
            <input type="file" name="file">
            <input type="submit" value="导入excel">
 </form>
demo https://blog.csdn.net/phil_jing/article/details/78307819
huang_zi 2018-05-17
  • 打赏
  • 举报
回复
页面: 文件上传: <form enctype="multipart/form-data" method="post" action="/uploadimg">图片<input type="file" name="file"/> <input type="submit" value="上传"/> </form> 后台:这个文件上传不只是可以上传excel,也可以是图片,txt文件等 @RequestMapping(value = "/uploadimg", method = RequestMethod.POST) public @ResponseBody String uploadImg(@RequestParam("file") MultipartFile file, HttpServletRequest request) { String contentType = file.getContentType(); String fileName = file.getOriginalFilename(); System.out.println("fileName-->" + fileName); System.out.println("getContentType-->" + contentType); // String filePath = request.getSession().getServletContext().getRealPath("templates/imgupload/"); //指定文件存放路径,可以是相对路径或者绝对路径 String filePath = "./src/main/resources/templates/imgupload/"; try { uploadFile(file.getBytes(), filePath, fileName); } catch (Exception e) { // TODO: handle exception } //返回json return "uploadimg success"; }
huang_zi 2018-05-17
  • 打赏
  • 举报
回复
哦,对了,还少了一个uploadFile方法,在这里加上 public static void uploadFile(byte[] file, String filePath, String fileName) throws Exception { File targetFile = new File(filePath); if (!targetFile.exists()) { targetFile.mkdirs(); } FileOutputStream out = new FileOutputStream(filePath + fileName); out.write(file); out.flush(); out.close(); }

81,091

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧