Reputation: 97
I have an endpoint for updating some Order details. This endpoint receives a DTO with updates.
@PutMapping
public void updateOrder(OrderUpdateDTO updates)
The problem is when I use @PostMapping everything works fine and my request successfully binds to an object. But when I use @PutMapping all my fields are nulls. When I looked into request object itself - it doesn't have any parameters at all.
Possible solution could be to mark a method argument with @RequestBody but the issue is that one of the fields in updates
is a file so I submit the whole form as a FormData object (which I cannot access with @RequestBody).
I couldn't find any mentions in Spring docs about the fact why POST automatically binds requests to classes and PUT does not.
So I have 2 questions:
Upvotes: 0
Views: 614
Reputation: 453
Did you try to use separate Multipartfile
from RequestBody
and use RequestParam
?
@PutMapping
public Foo updateOrder(
@RequestPart UpdateOrderDto updates,
@RequestPart MultipartFile file)
In the above case, you need to put 2 fields into form, updates
and file
.
Upvotes: 0