我遇到错误
"Resolved[org.springframework.web.multipart.support.MissingServletRequestPartException: Required request part 'file' is not present]"
我尝试了以前的文章中提供的所有选项,但没有用,请告诉我我在做错什么,这是我的第一个spring-boot应用程序。
我的控制器
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
import java.io.File;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
@RestController
public class SpringBootJdbcController {
@Autowired
JdbcTemplate jdbc;
@Autowired
private SpringBootJdbcService springBootJdbcService;
@RequestMapping("/insert")
public String index() {
jdbc.execute("insert into user(name,email)values('javatpoint','java@javatpoint.com')");
return "data inserted Successfully";
}
@CrossOrigin(origins = "http://localhost:4200")
@ResponseStatus(HttpStatus.OK)
@RequestMapping(value = "/uploadFile", method = RequestMethod.POST, consumes = "multipart/form-data")
public void uploadFiles(@RequestParam("file") MultipartFile file) throws Exception {
System.out.println("hello hello hello");
System.out.println("file---------" + file);
springBootJdbcService.readConfigData(file);
}
}
我的Application.properties
spring.servlet.multipart.max-file-size=10MB
spring.servlet.multipart.max-request-size=11MB
api呼叫邮递员图片:-
我不明白这是什么问题。这是我的第一个spring-boot应用程序,请帮忙。