国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Jfinal框架下結合ajaxFileupload實現多文件上傳

2019-11-10 17:44:31
字體:
來源:轉載
供稿:網友

距離寫代碼時間有點長了,沒有及時總結,現在忘得差不多了。不過大概思路還在,也是有點參考價值的!

demo下載

思路:

由于jfinal框架自身的問題,在實現多文件上傳時很難獲取所有文件的名字,只能獲取到一個input標簽里面的名字而已,重寫框架是最佳的方法,但是對于初學者而言十分艱難,所以我這里介紹另一種解決思路吧!

思路:

1、前端界面一個input標簽,使用AjaxFileupload.js實現對文件的上傳。

2、后臺接收所有文件,保存到一個獨一無二的文件夾中

3、遍歷該文件夾里面的所有文件,獲取他們的名字,存入數據庫

具體代碼如下:

前端界面:

<!-- 上傳 --><input type="file" name="uploadfile" id="uploadfile" multiple="multiple">監測點id:<input type="text" id="monPointId"><br>描述:<input type="text" id="description"><br>拍攝地點:<input type="text" id="location"><br><button id="upload" type="button" onclick="return false;">上傳</button><!-- 上傳js文件,放到最后加載 --><script type="text/javascript" src="${contextPath}/resources/js/jquery-1.11.1.js"></script><script type="text/Javascript" src="${contextPath}/resources/js/ajaxfileupload.js"></script><script type="text/javascript" src="${contextPath}/resources/js/upload.js"></script>js:

$(document).ready(function() {	$('#upload').click(function() {		upload();   	});});function upload() {	var monPointId=$("#monPointId").val();	var description=$("#description").val();	var location=$("#location").val();	$.ajaxFileUpload({		url : '/upload?monPointId='+monPointId+'&description='+description+'&location='+location,   //提交的路徑		type: 'post',		secureuri : false, // 是否啟用安全提交,默認為false		fileElementId : 'uploadfile', // file控件id		dataType : 'json',		data:{			'monPointId' : monPointId,			'description' : monPointId,			'location' : monPointId,		},		success : function(data, status) {			console.log("aa");			console.log(data);			console.log(status);		},		error : function(data, status) {			alert("上傳失敗");		}	});}后臺:

	/**	 * 多視頻文件上傳	 */	@SupPRessWarnings("unchecked")	public void upload(){		String dirName=CommonUtils.getCurrentTime();		String contextPath = PathKit.getWebRootPath();		String path = "/upload/video/" +dirName;		String pathUrl = contextPath + path;		Map<String,Object> map=new LinkedHashMap<String, Object>();		try {			List<UploadFile> uploadFile = getFiles("video/"+dirName);//在磁盤上保存文件			System.out.println(uploadFile.size());			String monPointId=getPara("monPointId");			String description=new String(getPara("description").getBytes("iso-8859-1"),"utf-8");//亂碼控制			String location=new String(getPara("location").getBytes("iso-8859-1"),"utf-8");			SensorService service=new SensorService();			map=(Map<String, Object>) service.uploadVideo(uploadFile, dirName, path,pathUrl, monPointId, description, location);		} catch (Exception e) {			e.printStackTrace();			map.put("status", false);			map.put("msg", "服務器異常!");			ExcelImportUtil.deleteDir(new File(pathUrl));		}		System.out.println(map);		renderJson(map);	}demo下載


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 阜平县| 房产| 突泉县| 内黄县| 湛江市| 合川市| 吴江市| 自治县| 绥中县| 武威市| 原阳县| 登封市| 商丘市| 合山市| 册亨县| 自贡市| 玉田县| 屏东市| 铜梁县| 芷江| 南部县| 永平县| 宁武县| 剑阁县| 峨边| 明水县| 平顶山市| 三都| 麻阳| 凯里市| 祥云县| 平南县| 祥云县| 郑州市| 万山特区| 琼结县| 大连市| 巢湖市| 石嘴山市| 根河市| 平江县|