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!";
    }
}
相关推荐
冒泡的肥皂26 分钟前
JAVA-WEB系统问题排查闲扯
java·spring boot·后端
只会AI搜索得coder1 小时前
sqlite3 sqlcipher加密,解密,集成springboot,读取sqlcipher加密工具
java·spring boot·sqlite
kinlon.liu1 小时前
SpringBoot整合Redis限流
spring boot·redis·后端
努力的搬砖人.4 小时前
Spring Boot集成MinIO的详细步骤
java·spring boot·后端
工业互联网专业6 小时前
基于springboot+vue的数码产品抢购系统
java·vue.js·spring boot·毕业设计·源码·课程设计·数码产品抢购系统
敖云岚6 小时前
【AI】SpringAI 第二弹:接入 DeepSeek 官方服务
java·人工智能·spring boot·后端·spring
axinawang6 小时前
Spring Boot管理Spring MVC
spring boot·spring·mvc
eternal__day6 小时前
MyBatis-Plus 详解:快速上手到深入理解
java·spring boot·后端·spring·java-ee·maven·mybatis
wasteland~6 小时前
MyBatis:SpringBoot结合MyBatis、MyBatis插件机制的原理分析与实战
spring boot·mybatis·插件机制·jdk代理
〆、风神6 小时前
Spring Boot 自定义定时任务组件深度解析:Quartz 集成与设计模式实战
spring boot·后端·设计模式