spring boot接收参数

接收content-type=multipart/form-data的表单数据

java 复制代码
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/api")
public class FormDataController {

    @PutMapping(value = "/submit", consumes = "multipart/form-data")
    public String handleFormData(@RequestParam Map<String, String> formData, 
                  @RequestParam(value = "file", required = false) MultipartFile file) {
        // 输出表单数据
        formData.forEach((key, value) -> System.out.println(key + ": " + value));

        // 如果上传了文件,打印文件信息
        if (file != null) {
            System.out.println("File name: " + file.getOriginalFilename());
        }

        return "Form data received successfully!";
    }
}
相关推荐
小王师傅6612 分钟前
【轻松入门SpringBoot】actuator健康检查(上)
java·spring boot·后端
JIngJaneIL1 小时前
基于java+ vue农产投入线上管理系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot
java1234_小锋3 小时前
[免费]SpringBoot+Vue勤工助学管理系统【论文+源码+SQL脚本】
spring boot·后端·mybatis·勤工助学
❀͜͡傀儡师4 小时前
SpringBoot 扫码登录全流程:UUID 生成、状态轮询、授权回调详解
java·spring boot·后端
a努力。4 小时前
国家电网Java面试被问:Spring Boot Starter 制作原理
java·spring boot·面试
一 乐4 小时前
酒店预约|基于springboot + vue酒店预约系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·后端
Code blocks5 小时前
SpringBoot从0-1集成Minio对象存储
java·spring boot·后端
JIngJaneIL6 小时前
基于java+ vue交友系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot·交友
苹果酱05676 小时前
解决linux mysql命令 bash: mysql: command not found 的方法
java·vue.js·spring boot·mysql·课程设计