JEECG通用文件上传-弹出式(觉得文件上传不好用的来看)

jeecg 文件上传,相信让很多人头痛吧?

首先是提交的方式,和表单一起提交,继承附件实体。
然后是多文件上传,样式冲突,各种各样的问题。

这里给一个比较通用的文件上传方案,还是基于uploadify标签。但是绝对好用!
step.1
新建一个文件上传的jsp页面,作为通用上传。
路径:/webpage/system/upload/uploadView.jsp
代码:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@include file="/context/mytags.jsp"%>
<!DOCTYPE html >
<html>
<head>
<t:base type="jquery,easyui,tools"></t:base>
<script type="text/javascript">

        function uploadSuccess(d,file,response){
                $("#fileUrl").val(d.attributes.url);
                $("#fileName").val(d.attributes.name);
                var url = $("#fileUrl").val();
                var html="";
                if(url.indexOf(".gif")!=-1 || 
                                url.indexOf(".jpg")!=-1        ||
                                url.indexOf(".png")!=-1 ||
                                url.indexOf(".bmp")!=-1){
                        html += "<img src='"+url+"' width =400 height=300 />";
                }else{
                        html += "<a href='"+url+"' target=_blank >下载:"+d.attributes.name+"</a>";
                }
                $("#fileShow").html(html);
        }
        function uploadCallback(callback){
                var url = $("#fileUrl").val();
                var name= $("#fileName").val();
                callback(url,name);
                
        }
</script>
</head>
<body style="overflow-y: hidden" scroll="no">
  <table cellpadding="0" cellspacing="1" class="formtable">
  <input id="documentTitle" type="hidden" name="documentTitle" value="blank"/>
  <input id="fileUrl" type="hidden"/>
  <input id="fileName" type="hidden"/>
   <tbody>
    <tr>
     <td align="right">
       <label class="Validform_label"></label>
     </td>
     <td class="value">
      <t:upload name="instruction" dialog="false" multi="false" extend="pic" queueID="instructionfile" view="false" auto="true" uploader="systemController.do?saveFiles" onUploadSuccess="uploadSuccess"  id="instruction" formData="documentTitle"></t:upload>
     </td>
    </tr>
    <tr>
     <td colspan="2" id="instructionfile" class="value">
     </td>
    </tr>
   </tbody>
  </table>
   <div id="fileShow" >
  </div>
</body>
</html>

step.2
写一个通用的js方法,来调用这个文件上传窗口
可以写入curdtools.js中

function commonUpload(callback){
         $.dialog({
                        content: "url:systemController.do?commonUpload",
                        lock : true,
                        title:"文件上传",
                        width:700,
                        height: 400,
                        parent:windowapi,
                        cache:false,
                    ok: function(){
                            var iframe = this.iframe.contentWindow;
                            iframe.uploadCallback(callback);
                                return true;
                    },
                    cancelVal: '关闭',
                    cancel: function(){
                    } 
                });
}

或者

//通用弹出式文件上传
function commonUpload(callback){
    $.dialog({
           content: "url:systemController.do?commonUpload",
           lock : true,
           title:"文件上传",
           zIndex:2100,
           width:700,
           height: 200,
           parent:windowapi,
           cache:false,
       ok: function(){
               var iframe = this.iframe.contentWindow;
               iframe.uploadCallback(callback);
                   return true;
       },
       cancelVal: '关闭',
       cancel: function(){
       } 
   });
}
function browseImages(inputId, Img) {// 图片管理器,可多个上传共用
}
function browseFiles(inputId, file) {// 文件管理器,可多个上传共用
}
function decode(value, id) {//value传入值,id接受值
	var last = value.lastIndexOf("/");
	var filename = value.substring(last + 1, value.length);
	$("#" + id).text(decodeURIComponent(filename));
}

step.3
在/src/jeecg/system/controller/core/SystemController.java 中添加弹出页面跳转的方法

/**
         * 文件上传通用跳转
         * 
         * @param icon
         * @param req
         * @return
         */
        @RequestMapping(params = "commonUpload")
        public ModelAndView commonUpload(HttpServletRequest req) {
                return new ModelAndView("system/upload/uploadView");
        }

复制代码
这样就大功告成了!
使用时只需要:
function uploadTaxRegImgCallBack(url,name){
$("#taxRegImgView").attr(‘src’,url);
$("#taxRegImg").val(url);
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值