• springMVC多文件上传


    效果:

     代码:

    demo.jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>上传附件</title>
    </head>
    <body>
        <form method="POST" enctype="multipart/form-data" id="upload">
            附件选择 :<input type="file" name="upload" multiple="multiple">
            <button type="button" onclick="uploadFile();">上传附件</button>
        </form>
    <script type="text/javascript" src="static/js/jquery-easyui/jquery.min.js"></script>
    <script type="text/javascript">
    function uploadFile() {
        var form = document.getElementById('upload');//获取form表单的内容
        formData = new FormData(form);//
        $.ajax({
            url: "demo",
            type: "post",
            data: formData,
            processData: false,//不处理数据
            contentType: false,//不处理内容类型
            success: function (data) {
                if (data == 'ok') {
                    alert("上传成功!");
                }
            }
        })
    }
    </script>
    </body>
    </html>

    demo.java

        @RequestMapping("/demo")
        @ResponseBody
        public String demo(@RequestBody List<MultipartFile> upload) {
            if (upload != null&&upload.size()>0) {
                for (MultipartFile multipartFile : upload) {
                    System.out.println(multipartFile.getOriginalFilename());
                }
            }
            return "ok";
        }
  • 相关阅读:
    react脚手架搭建及配置
    mac使用技巧
    nginx配置
    vue常见前端UI库
    自定义指令
    代码缩进修改
    webpack学习入门
    webpack使用extract-text-webpack-plugin打包时提示错误
    webpack未成功全局安装
    基于jQuery的AJAX实现三级联动菜单
  • 原文地址:https://www.cnblogs.com/jiefu/p/10607179.html
Copyright © 2020-2023  润新知