SpringBoot实现文件的上传以及表单数据的同时提交

本文介绍了如何在SpringBoot应用中实现文件和表单数据的上传。前端利用Ajax通过FormData对象提交,后端展示处理过程,并讨论可能遇到的错误。涉及的技术包括jQuery、MySQL和MongoDB。
摘要由CSDN通过智能技术生成

SpringBoot实现文件以及表单数据的上传

一、前期准备

yml文件

 spring:
   servlet:
    multipart:
      max-file-size: 10MB  #文件上传的最大大小
      file-size-threshold: 10MB

pom文件

    <!--文件的上传下载-->
        <!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.4</version>
        </dependency>

二、前端页面

通过表单传递图片文件的同时上传表单中的数据

 <form method="post" class="form-x" enctype="multipart/form-data" id="registerForm">
                            <!--教练-->
                            <div class="form-group">

                                <div class="label">
                                    <label>球队名称:</label>
                                </div>
                                <div class="field">
                                    <input id="teamName" type="text" class="input w50" value="" name="name"
                                           placeholder="请输入4-6位汉字"/>
                                    <div class=""><span style="margin-left: 30px;color:red" hidden="hidden"
                                                        id="warn"></span></div>
                                </div<
  • 4
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值