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!";
    }
}
相关推荐
用户31268748772016 小时前
AI Agent 开发实战(六):用 Spring AI 搭建你的第一个 Agent
spring boot·openai
zhangjw3417 小时前
第36篇:Spring Boot进阶:Web开发+参数校验+全局异常处理
前端·spring boot·后端
完美火龙篇 四月的友17 小时前
SpringBoot 即时聊天 IM 完整实现(HTTP会话管理 \+ WebSocket实时推送 \+ 离线消息)
spring boot·websocket·http
Bug收容所18 小时前
12305项目学习day5
java·spring boot·redis·mysql·spring·rocketmq
小Ti客栈1 天前
Spring Boot 集成 Springdoc-OpenAPI 与 Knife4j实现接口文档与可视化调试
java·spring boot·后端
paopaokaka_luck1 天前
基于Springboot3+Vue3的高校选课系统(AI选课助手、协同过滤算法、分享到微博、扣扣、Echarts图形化分析)
网络·spring boot·网络协议·echarts
小Ti客栈2 天前
Spring Boot 整合 Swagger2 和 Knife4j实现接口文档与可视化调试
java·spring boot·后端
2601_963870172 天前
【计算机毕业设计】基于Spring Boot的社区老年大学课程报名与学习系统的设计与实现
java·spring boot·学习
weixin_BYSJ19872 天前
springboot3家政平台小程序--附源码00904
java·javascript·spring boot·python·django·flask·php