分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 技术分享

Layer文件上传操作

发布时间:2023-09-06 01:33责任编辑:蔡小小关键词:文件上传

1:upload.html

<!DOCTYPE html><html lang="en"><head> ???<meta charset="UTF-8"> ???<title></title> ???<link rel="stylesheet" href="./layui/css/layui.css" media="all"></head><body> ???<div class="layui-container"> ???????<div class="layui-row" align="center" style="margin-top: 30px;"> ???????????<button type="button" class="layui-btn" id="upload"> ???????????????<i class="layui-icon">&#xe67c;</i>选择文件</button> ???????</div> ???????<div class="layui-row" align="center" style="margin-top: 30px;"> ???????????<textarea id="result" cols="50" rows="10"></textarea> ???????</div> ???</div></body><script src="./jquery/jquery.min.js"></script><script src="./layui/layui.js"></script><script> ???layui.use(‘upload‘, function(){ ???????var upload = layui.upload; ???????//执行上传 ???????var uploadInst = upload.render({ ???????????elem: ‘#upload‘ //绑定元素 ???????????,url: ‘/ssfwpt/ra/ramanage‘ //上传接口 ???????????,method: ‘POST‘ ???????????,accept: ‘file‘ ???????????,size: 50 ???????????,before: function(obj){ ???????????????layer.load(); ???????????} ???????????,done: function(res){//上传完毕回调 ???????????????layer.closeAll(‘loading‘); ???????????????var result = ‘‘; ???????????????for(var i=0; i<res.length; i++){ ???????????????????result = result + res[i].nsrsbh+"="+res[i].container+"\n"; ???????????????} ???????????????$("#result").html(result); ???????????} ???????????,error: function(){//请求异常回调 ???????????????layer.closeAll(‘loading‘); ???????????????layer.msg(‘网络异常,请稍后重试!‘); ???????????} ???????}); ???});</script></html>

2:后台(Spring-boot)

/** ????* 实现文件上传 ????* */ ???@RequestMapping(value = "/ramanage", method = RequestMethod.POST) ???@ResponseBody ???public List<Map<String,String>> ramanage(@RequestParam("file") MultipartFile file){ ???????List<Map<String,String>> result = new ArrayList<>(); ???????try { ???????????InputStream input = file.getInputStream(); ???????????Workbook wb = new HSSFWorkbook(input); ???????????Sheet sheet = wb.getSheetAt(0); ???????????int rowNum = sheet.getLastRowNum()+1; ???????????Map<String,String> map; ???????????for(int i=1; i<rowNum; i++){ ???????????????Row row = sheet.getRow(i); ???????????????//容器名称 ???????????????Cell containerCell = row.getCell(0); ???????????????String container = containerCell.getStringCellValue(); ???????????????//税号 ???????????????Cell nsrsbhCell = row.getCell(1); ???????????????String nsrsbh = nsrsbhCell.getStringCellValue(); ???????????????map = new HashMap<>(); ???????????????map.put("nsrsbh", nsrsbh); ???????????????map.put("container", container); ???????????????result.add(map); ???????????} ???????} catch (IOException e) { ???????????e.printStackTrace(); ???????} ???????return result; ???}

Layer文件上传操作

原文地址:https://www.cnblogs.com/yshyee/p/8137319.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved