摘要:引入的文件這個(gè)可以去找首先創(chuàng)建一個(gè)代碼額外添加的數(shù)據(jù),后臺(tái)有取得單位為,如果為表示不限制文件大小設(shè)置
引入的文件
<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-fileinput/4.4.9/css/fileinput.min.css" media="all" rel="stylesheet" type="text/css" /> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css"> <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-fileinput/4.4.9/css/fileinput.min.css" media="all" rel="stylesheet" type="text/css" /> <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-fileinput/4.4.9/css/fileinput-rtl.min.css" media="all" rel="stylesheet" type="text/css"/> <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" media="all" rel="stylesheet" type="text/css" /> <script src="https://code.jquery.com/jquery-3.2.1.min.js">script> <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-fileinput/4.4.9/js/plugins/piexif.min.js" type="text/javascript">script> <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-fileinput/4.4.9/js/plugins/sortable.min.js" type="text/javascript">script> <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-fileinput/4.4.9/js/plugins/purify.min.js" type="text/javascript">script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js">script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" type="text/javascript">script> <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-fileinput/4.4.9/js/fileinput.min.js">script> <script type="text/javascript" src="../../static/bootstrap/js/zh.js">script>
首先創(chuàng)建一個(gè)div
<div class="file-loading"> <input id="input-file-1" name="fileName" multiple type="file" accept="image/*" > div>
javascript代碼
后臺(tái)代碼
@ResponseBody @RequestMapping(value="/add",method = RequestMethod.POST) public String insertGoods(@RequestParam("fileName") MultipartFile imageFile[], //同步上床 獲取多張圖片參數(shù) /*Goods goods,*/ HttpServletRequest request){ System.out.println("hello world"); Goods goods = new Goods(); if(imageFile!=null){ String imgUrl=""; for(int k=0;k) { imgUrl += saveImageFile(imageFile[k], request)+","; } goods.setImgUrl(imgUrl); } Date date=new Date(); goods.setUploadTime(date); GoodsEnum anEnum=goodsService.insertGoods(goods); if(anEnum.equals(GoodsEnum.INSERT_GOODS_SUCCESS)){ return JSONUtil.toJSON("success"); }else{ return JSONUtil.toJSON("error"); } }
private String saveImageFile(MultipartFile imageFile, HttpServletRequest request) { //獲取文件上傳到服務(wù)器的路徑 String uploadUrl=getRealPath(request)+"static/uploadImg/"; System.out.println("文件路徑為:"+uploadUrl); //獲取從客戶(hù)端傳過(guò)來(lái)的文件名 String filename=imageFile.getOriginalFilename(); //判斷文件上傳的路徑是否存在,若不存在,則需要?jiǎng)?chuàng)建它 File dir=new File(uploadUrl); if(!dir.exists()){ dir.mkdirs(); } //targetFile最終上傳的文件,先判斷文件是否存在 File targetFile=new File(uploadUrl+filename); if(!targetFile.exists()){ //如果文件不存在,我們嘗試創(chuàng)建它 try { targetFile.createNewFile(); }catch (IOException e){ e.printStackTrace(); } } //使用MultipartFile的transferTo方法保存文件 try { imageFile.transferTo(targetFile); }catch (IllegalStateException e){ e.printStackTrace(); }catch (IOException e){ e.printStackTrace(); } return "img/"+filename; }
文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉(zhuǎn)載請(qǐng)注明本文地址:http://www.ezyhdfw.cn/yun/1689.html
項(xiàng)目中經(jīng)常會(huì)遇到文件上傳,管理多文件上傳過(guò)程的需求。bootstrap file input組件算是不錯(cuò)的解決方案 showImg(https://segmentfault.com/img/bVbegps?w=1146&h=596); 項(xiàng)目Github地址:https://github.com/kartik-v/b... 除此之外還有一個(gè)官方在線(xiàn)文檔,提供各種示例:http://plugins.k...
摘要:默認(rèn)為選擇上傳的文件數(shù)超出了允許的最大限制。在這種情況下,每一個(gè)人選擇的文件被上傳成功后,觸發(fā)事件。此事件僅在上傳和完成同步或異步批量上傳后觸發(fā)。 下載地址、API和DOM地址(英語(yǔ)好的小伙伴可以看看) 下載地址:https://github.com/kartik-v/b...API文檔 :http://plugins.krajee.com/fil...D E M O:http://p...
摘要:老姚淺談怎么學(xué)鑒于時(shí)不時(shí),有同學(xué)私信問(wèn)我老姚,下同怎么學(xué)前端的問(wèn)題。擼碼聽(tīng)歌,全局控制。 淺析用 js 解析 xml 的方法 由于項(xiàng)目上需要解析 xml,于是各種百度,然后自己總結(jié)了下各個(gè)主流瀏覽器解析 xml 的方法,只能是很淺顯的知道他的用法,但是還沒(méi)有深層次的研究。 裝 X - 建立自己的斗圖網(wǎng)站庫(kù) 之前加過(guò)一個(gè)斗圖群,看到很多經(jīng)典的表情,然后就收藏到了 QQ, 迫于本屌絲開(kāi)不起...
摘要:今天我就來(lái)講講插件的使用,它是如何實(shí)現(xiàn)列表表頭自定義顯示字段的,我把我的經(jīng)驗(yàn)分享出來(lái),滿(mǎn)足一下不懂英語(yǔ)的人,給你們搭個(gè)快車(chē)。需求分析實(shí)現(xiàn)列表表頭自定義顯示字段,自定義表頭排序。 序言 Yii2框架的擴(kuò)展性能真的很不錯(cuò),很多效果都可以通過(guò)插件去實(shí)現(xiàn),你想不到的老外都幫你想好了,于是,人群中就流傳了這么一句話(huà):效果不會(huì)寫(xiě)不要緊,會(huì)用插件也不錯(cuò)。GitHub是一個(gè)龐大而且開(kāi)放的資源庫(kù),平時(shí)有...
摘要:圖片存儲(chǔ)的方式為存儲(chǔ)在虛擬目錄下并返回虛擬目錄的路徑。如果是將開(kāi)發(fā)的包直接部署在服務(wù)器中,則參考配置虛擬目錄。 序言:項(xiàng)目環(huán)境 本次簡(jiǎn)單的demo是建立在springmvc框架上的,部署環(huán)境為tomcat,前段使用的bootstrap+jquery_file_upload組件。圖片存儲(chǔ)的方式為存儲(chǔ)在虛擬目錄下并返回虛擬目錄的路徑。建議先搭配好springmvc環(huán)境再繼續(xù)參考本博客。沒(méi)有...
閱讀 847·2023-04-25 19:43
閱讀 4115·2021-11-30 14:52
閱讀 3930·2021-11-30 14:52
閱讀 4027·2021-11-29 11:00
閱讀 3922·2021-11-29 11:00
閱讀 4039·2021-11-29 11:00
閱讀 3770·2021-11-29 11:00
閱讀 6608·2021-11-29 11:00