【发布时间】:2022-01-04 00:27:34
【问题描述】:
我已经看到了很多来源,也看到了一些关于 SO 的问题,但没有找到解决方案。
我想向我的 Spring 应用发送包含 JSON 对象 Car 和附件的 POST/PUT 请求。
目前我有一个 CarController 可以正确使用 JSON 对象
@PutMapping("/{id}/update")
public void updateCar(@PathVariable(value = "id") Long carId, @Validated @RequestBody Car car) throws ResourceNotFoundException {
// I can work with received car
}
我还有一个 FileController 可以与 file 正确配合
@PostMapping("/upload")
public void uploadFiles(@RequestParam("file") MultipartFile file) throws IOException {
// I can work with received file
}
但是我的方法应该如何才能同时使用car 和file?这段代码没有提供任何car 或file。
@PutMapping("/{id}/update")
public void updateCar(@PathVariable(value = "id") Long carId, @Validated @RequestBody Car car, @RequestParam("file") MultipartFile file) throws ResourceNotFoundException, IOException {
// can not work neither with car nor with file
}
【问题讨论】:
标签: java json spring http multipartform-data