• Layer文件上传操作


    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+"
    ";
                    }
    
                    $("#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;
        }
  • 相关阅读:
    [Windwos Phone 7] Accelerometer
    [Windwos Phone 7] 获取设备相关信息
    实现ZUNE上软件商城的软件星级推荐效果
    [Windows Phone 7]如何判断手机是否有网络连接
    [Windows Phone 7]UI对屏幕的自适应的处理
    [Windows Phone 7]开发分享图片的插件(2)
    [Windows Phone 7]如何导航页面和页面间传值
    windows phone 从cer中提出公钥然后再RSA加密的问题
    异步上传文件插件AjaxFileUploader在Asp.net MVC中应用
    微软认证考试分析
  • 原文地址:https://www.cnblogs.com/yshyee/p/8137319.html
Copyright © 2020-2023  润新知