*1.BootStrap-FileInputプラグインGITダウンロードアドレス
https://github.com/kartik-v/bootstrap-fileinput.git
2。bootstrap-fileinputの使用を解決して、返品値を取得します
写真をアップロードします
$( "#file-0a")。fileInput({uploadurl: "/upload_img"、//画像をアップロードするためのurlallowedfileextensionsをアップロードしました:['jpg'、 'png'、 'gif']、oburwiteInitial:oburwiteInitial:fals、maxfilesize:1000、uploaded the uploadedファイルの最大数InitialCaption: "Merchant Logoをアップロードしてください"、//初期テキストボックス値画像イベントをアップロードした後、返品値の作成方法を取得することに注意してください
$( '#file-0a')。
JSPページ
<input id = "file-0a" type = "file" multipledata-min-file-count = "1" name = "upload_logo">
ここで、data-min-file-count =” 1”は、アップロードされたファイルの最小数を指します
3。サーバーコード
Spring独自のプラグインを使用してアップロードすると、フレームワークはSpringMVCです
豆
Import java.util.list; public class picture {private list <string> paths; public list <string> getPaths(){return paths;} public void setPaths(list <string> paths){this.paths = paths;}}}}コントローラ
@ResponseBody@requestMapping(value = "upload_img"、method = requestmethod.post)public picture uploadimage(@requestparam multipartfile [] upload_logo)throws ioexception {log.info( "upload picture"); picture pic = new acture> list <string> ring = new Arraylist <string>; uploadutil.getFolder(); } else {log.info( "ファイル長:" + myfile.getSize()); log.info( "ファイルタイプ:" + myfile.getContentType()); log.info( "ファイル名:" + myfile.getName()); log.info( "ファイル名:" + myfile.getoriginalfilename()); log.info( "================================================================================== =========================================================================================== =========================================================================================== =========================================================================================== uploadutil.writefile(myfile.getoriginalfilename()、dir、myfile.getinputStream()); log.info( "file path:"+path); paths.add(path);}} pic.setpaths; return pic;}}uploadutil
Private static Final Logger log = loggerFactory.getLogger(uploadutil.class); private uploadutil(){} private static simpledateformat fullsdf = new simpledateFormat( "yyyymmdhhmmsssssss"); private static simpledateformatフォルダー= new simpledateFormat( "yyyy" + file.separator + "mm" + file.separator + "dd");/*** yyyy file.separator mm file.separator dd format string* @return*/public static string getfolder(){return folder.folder.folder.folder.ful(new ford(file(file(file(file(file(file(file(file(bed(file))))) srcname*元のファイル名* @param dirname*ディレクトリ名* @param入力*入力ストリーム保存* @returnデータベースに保存するパスを返します*/public static string writefile(string srcname、string dirname、inputstream input)ioexception {log.info(srcname); Tomcatのserver.xml文字列uploaddir = contextutil.getSysprop( "upload_dir"); // uploadパス// virtual directory string virtualdir = contextsutil.getsysprop( "virtual_dir"); srcname.substring(srcname.indexof( "。"));} else {srcname = ".jpg";} string filename = ""; // filename = uploaddir + file.separator + dirname + file.separator + fullsdf. fied(new date(new)filed(new dig) + filetator + filedatデータ文字列へSavePath = filename.Replace(uploadDir、 ""); savepath = virtualdir + savepath.replace( "//"、 "/"); file file = new file(filename); if(!file.getParentFile()。 FileOutputStream(file); // 1回30kbbyte [] readbuff = new byte [1024 * 30]; int count = -1;4.アップロード中に遭遇したいくつかの問題を解決します
クリックしてアップロードしている場合、進行状況バーは100%として表示され、JSPページに[Object、Obejct]が表示され、返されたJSONオブジェクトが背景にあるかどうかに注意してください。
上記は、BootstrapのFileInputプラグインの方法で、エディターが紹介した複数のファイルアップロードを実装しています。それがあなたに役立つことを願っています。ご質問がある場合は、メッセージを残してください。編集者は時間内に返信します。 wulin.comのウェブサイトへのご支援ありがとうございます!