Angular.js ng-file-upload結(jié)合springMVC的使用教程
前言
本文主要給大家介紹了關(guān)于Angular.js文件上傳控件ng-file-upload結(jié)合springMVC使用的相關(guān)內(nèi)容,對(duì)于Angular.js文件上傳控件ng-file-upload不熟悉的朋友們可以先看看這篇文章(傳送門),下面話不多說,來看看詳細(xì)的使用介紹:
引入angular和ng-file-upload。
前端代碼
Upload.upload({ url: 'upload', fields: {'username': 'zouroto'}, // additional data to send file: file }).progress(function (evt) { var progressPercentage = parseInt(100.0 * evt.loaded / evt.total); console.log('progress: ' + progressPercentage + '% ' + evt.config.file.name); }).success(function (data, status, headers, config) { console.log('file ' + config.file.name + 'uploaded. Response: ' + data); });
springMVC代碼:
@Controller public class UiController { @ResponseStatus(HttpStatus.OK) @RequestMapping(value = "/upload") public void upload(@RequestParam("file") MultipartFile file, @RequestParam("username") String username ) throws IOException { byte[] bytes; if (!file.isEmpty()) { bytes = file.getBytes(); //store file in storage } System.out.println(String.format("receive %s from %s", file.getOriginalFilename(), username)); } }
application config
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"> <property name="maxUploadSize" value="5000000"/> </bean>
maven
<dependency> <groupId>commons-fileupload</groupId> <artifactId>commons-fileupload</artifactId> <version>1.3.1</version> </dependency>
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對(duì)腳本之家的支持。
相關(guān)文章
基于angular6.0實(shí)現(xiàn)的一個(gè)組件懶加載功能示例
這篇文章主要介紹了基于angular6.0實(shí)現(xiàn)的一個(gè)組件懶加載功能示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-04-04AngularJS實(shí)現(xiàn)表單元素值綁定操作示例
這篇文章主要介紹了AngularJS實(shí)現(xiàn)表單元素值綁定操作,結(jié)合具體實(shí)例形式分析了AngularJS針對(duì)表單元素屬性相關(guān)操作技巧,需要的朋友可以參考下2017-10-10AngularJS基礎(chǔ)學(xué)習(xí)筆記之表達(dá)式
AngularJS表達(dá)式用于應(yīng)用程序數(shù)據(jù)綁定到HTML。表達(dá)式都寫在雙括號(hào)就像{{表達(dá)式}}。表達(dá)式中的行為跟ng-bind指令方式相同。 AngularJS應(yīng)用表達(dá)式是純javascript表達(dá)式,并輸出它們被使用的數(shù)據(jù)在那里。2015-05-05angularjs項(xiàng)目的頁面跳轉(zhuǎn)如何實(shí)現(xiàn)(5種方法)
本篇文章主要介紹了詳解angularjs項(xiàng)目的頁面跳轉(zhuǎn)如何實(shí)現(xiàn) ,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-05-05AngularJS動(dòng)態(tài)添加數(shù)據(jù)并刪除的實(shí)例
下面小編就為大家分享一篇AngularJS動(dòng)態(tài)添加數(shù)據(jù)并刪除的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-02-02angularJs復(fù)選框checkbox選中進(jìn)行ng-show顯示隱藏的方法
今天小編就為大家分享一篇angularJs復(fù)選框checkbox選中進(jìn)行ng-show顯示隱藏的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-10-10詳解如何構(gòu)建一個(gè)Angular6的第三方npm包
這篇文章主要介紹了詳解如何構(gòu)建一個(gè)Angular6的第三方npm包,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-09-09基于datepicker定義自己的angular時(shí)間組件的示例
這篇文章主要介紹了基于datepicker定義自己的angular時(shí)間組件,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-03-03