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

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

多圖片上傳

2019-11-09 17:46:05
字體:
來源:轉載
供稿:網友

1.div部分

		                       <div>						<span>添加圖片:</span> 						<span id="attrFieldUploader"							style="width: 150px;">							<div id="fileUploader" style="width:102px; height: 34px; display:inline" >								<input name="file[]" type="file" accept="image/jpg,image/png" style="width: 70px" multiple/>								<div class="easyui-PRogressbar" style="width: 170px"></div>							</div>						</span>     						<span id="preview" style="display: none">						<!-- 	<button onclick='c$.onLayout();return false;'>預覽</button>  							<button onclick='c$.onClearImage();return false;'>清除</button> -->						</span>					</div>	2.后臺處理

	@ResponseBody	@RequestMapping(value = "uploadx")  	public ActionResult uploadx(@RequestParam("cate") String category, @RequestParam("file[]") MultipartFile file, HttpServletRequest request, ModelMap model) {  		  		//保存  		try { 			String fileName = this.fileService.getFilePath(category, file.getOriginalFilename());			String path = this.fileService.resolveToPhysicalFileName(fileName);			File targetFile = new File(path);  			if(!targetFile.exists()){  				targetFile.mkdirs();  			}  			file.transferTo(targetFile);			return ActionResult.Succeed(fileName);		} catch (Exception e) {  			logger.warn("", e);			return ActionResult.Failed(e);		}  			}3.service

package com.eznext.modul.file.service;import java.io.File;import java.math.BigDecimal;import java.sql.Date;import java.util.Map;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.stereotype.Service;import com.eznext.core.util.md5;import com.eznext.core.web.BusinessException;@Servicepublic class FileService {	 private static Logger logger = LoggerFactory				.getLogger(FileService.class);	 	 private Map<String, String> categories;	 	 	 public String getFilePath(String category, String filename) throws BusinessException{		int index = filename.lastIndexOf(".");		 if(index < 0){			 throw new BusinessException("無效的文件名!");		 }		 String cateId = String.format("%s.name", category.toLowerCase());		 String name = categories.get(cateId);		 if(name == null)		 {			 throw new BusinessException("無效的屬性名!");		 }		 return name + "_" + uniqueName(filename.substring(0, index)) + "." + filename.substring(index + 1);	 }	 	 public String resolveToPhysicalFileName(String filename) throws BusinessException{		 int index = filename.indexOf("_");		 if(index < 0){			 throw new BusinessException("無效的文件名!");		 }		 String path = categories.get(String.format("%s.path", filename.subSequence(0, index)));		 if(path == null)		 {			 throw new BusinessException("無效的屬性名!");		 }		 return path + "/" + filename.substring(index + 1);	 }	 	 public void deleteFile(String filename) throws BusinessException{		 	String physicalFilename = this.resolveToPhysicalFileName(filename);			File file = new File(physicalFilename);			if(file.exists() && file.isFile()){				file.delete();			}	 }	 	 public Map<String, String> getCategories() {		return categories;	}	public void setCategories(Map<String, String> categories) {		this.categories = categories;	}	private String uniqueName(String name){		BigDecimal vv = new BigDecimal(System.currentTimeMillis());				return MD5.getMd5String(name + vv.toPlainString());	 }}4.配置文件

<bean id="fileService" class="com.eznext.modul.file.service.FileService">		<property name="categories">			<map>			    <entry key="maintain.name" value="maintain"></entry>			    <entry key="maintain.path" value="${fileservice.baseDir}/maintain"></entry>			</map>		</property>	</bean> 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 石屏县| 连城县| 清丰县| 喜德县| 武隆县| 璧山县| 顺昌县| 从江县| 金寨县| 肃宁县| 汝州市| 秦安县| 肇东市| 资兴市| 深圳市| 府谷县| 延津县| 明光市| 海宁市| 衢州市| 江华| 阿荣旗| 库车县| 武邑县| 隆子县| 天等县| 太保市| 衡阳县| 海淀区| 大余县| 沙雅县| 四平市| 永定县| 偏关县| 东乡县| 娄烦县| 仁化县| 浮山县| 从化市| 汶川县| 秀山|