layui upload上傳文件動態傳參,后台獲取不到值


廢話不多說,直接上代碼

js:

layui.use('upload', function(){
        var $ = layui.jquery,upload = layui.upload;
        //綁定原始文件域
        upload.render({
            elem: '#test20'
            ,url: "<c:url value='/order/imgUpload.do?proVal=IMG_PATH'/>" 
            ,auto: true
            ,accept: 'file'
            ,exts:"jpg|png|gif|jpeg|bmp"
            ,size:1024
            ,before: function(obj){
                var orderID = $("#orderID").val();
                this.data={"orderID":orderID}//攜帶動態參數
            }
            ,done: function(res){
                if(res.msg=='ok'){
                    alert('上傳成功');
                }else{
                    alert(res.msg);
                }
            }
        });
   });

 

java:

上傳文件的代碼我沒寫,主要寫了怎么取這個動態參數的值

@ResponseBody
@RequestMapping(
"/imgUpload") public JsonResult imgUpload( HttpServletRequest request,HttpServletResponse response,ModelMap map ){ JsonResult json = new JsonResult(); Integer orderID = null;//訂單ID DiskFileItemFactory factory = new DiskFileItemFactory(); factory.setSizeThreshold(10240000); try { ServletFileUpload upload = new ServletFileUpload(factory); upload.setHeaderEncoding("utf-8"); @SuppressWarnings("rawtypes") List fileList = null; try { fileList = upload.parseRequest(request); } catch (FileUploadException ex) { return null; } @SuppressWarnings("unchecked") Iterator<FileItem> it = fileList.iterator(); //取參數 while (it.hasNext()) { FileItem item = it.next(); if(item.isFormField()&&"orderID".equals(item.getFieldName())){ orderID = Integer.valueOf(item.getString()); } }

if(orderID==null){ json.setMsg("參數有誤,請刷新重試!"); return json; } } catch (Exception e) { e.printStackTrace(); json.setMsg("上傳失敗"); }finally{ factory = null; } return json; }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM