File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed
spring-boot-rest/src/main/java/com/baeldung/springpagination/controller Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change 1919
2020import java .text .ParseException ;
2121import java .util .List ;
22+ import java .util .Objects ;
2223import java .util .stream .Collectors ;
2324
2425@ Controller
@@ -65,7 +66,11 @@ public PostDto getPost(@PathVariable("id") Long id) {
6566
6667 @ PutMapping (value = "/{id}" )
6768 @ ResponseStatus (HttpStatus .OK )
68- public void updatePost (@ RequestBody PostDto postDto ) throws ParseException {
69+ public void updatePost (@ PathVariable ("id" ) Long id , @ RequestBody PostDto postDto ) throws ParseException {
70+ if (!Objects .equals (id , postDto .getId ())){
71+ throw new IllegalArgumentException ("IDs don't match" );
72+ }
73+
6974 Post post = convertToEntity (postDto );
7075 postService .updatePost (post );
7176 }
You can’t perform that action at this time.
0 commit comments