我在使用 Postman 将 Excel 文件上传到 Spring Boot 应用程序时遇到问题。我不断收到错误“当前请求不是多部分请求”。
我已经尝试了有关删除内容类型标头和选择表单数据的其他解决方案,但到目前为止没有任何效果。
这是我的控制器代码。
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.InputStreamResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.Set;
@CrossOrigin
@Controller
@RequestMapping("/player")
public class PlayerController {
@Autowired
PlayerService playerService;
@Autowired
TeamService teamService;
@PostMapping("/upload/{teamId}")
public ResponseEntity<ResponseMessage> uploadFile(@RequestPart("file") MultipartFile file, @PathVariable int teamId) {
String message;
if (ExcelHelper.hasExcelFormat(file)) {
try {
playerService.save(file, teamId);
message = "Uploaded the file successfully: " + file.getOriginalFilename();
return ResponseEntity.status(HttpStatus.OK).body(new ResponseMessage(message)); …Run Code Online (Sandbox Code Playgroud)