spring boot接收参数
接收content-type=multipart/form-data的表单数据
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!";
}
}
原文地址:https://blog.csdn.net/weixin_47503016/article/details/143830582
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!