接收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!";
}
}