这篇文章主要给大家介绍了关于Angular.js文件上传控件ng-file-upload结合springMVC的使用教程,文中通过示例代码介绍的非常详细,对大家具有一定的参考学习价值,需要的朋友们下面来一起看看吧。
前言
本文主要给大家介绍了关于Angular.js文件上传控件ng-file-upload结合springMVC使用的相关内容,对于Angular.js文件来源gaodaimacom搞#代%码网上传控件ng-file-upload不熟悉的朋友们可以先看看这篇文章(传送门),下面话不多说,来看看详细的使用介绍:
引入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
maven
commons-fileuploadcommons-fileupload1.3.1
总结
以上就是Angular.js ng-file-upload结合springMVC的使用教程的详细内容,更多请关注gaodaima搞代码网其它相关文章!