* BAEL-724 code for put/patch article

* BAEL-724 fix typo

* BAEL-728 more generic patch approach
This commit is contained in:
Tomasz Lelek
2017-03-24 15:29:14 +01:00
committed by pedja4
parent e884e3f924
commit 2d556cd763
4 changed files with 67 additions and 11 deletions

View File

@@ -1,14 +1,20 @@
package org.baeldung.repository;
import org.baeldung.web.dto.HeavyResource;
import org.baeldung.web.dto.HeavyResourceAddressPartialUpdate;
import org.baeldung.web.dto.HeavyResourceAddressOnly;
import java.util.Map;
public class HeavyResourceRepository {
public void save(HeavyResource heavyResource) {
}
public void save(HeavyResourceAddressPartialUpdate partialUpdate) {
public void save(HeavyResourceAddressOnly partialUpdate) {
}
public void save(Map<String, Object> updates, String id) {
}
}

View File

@@ -3,13 +3,12 @@ package org.baeldung.web.controller;
import org.baeldung.repository.HeavyResourceRepository;
import org.baeldung.web.dto.HeavyResource;
import org.baeldung.web.dto.HeavyResourceAddressPartialUpdate;
import org.baeldung.web.dto.HeavyResourceAddressOnly;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
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.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
@RestController
public class HeavyResourceController {
@@ -23,9 +22,16 @@ public class HeavyResourceController {
}
@RequestMapping(value = "/heavy", method = RequestMethod.PATCH, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> partialUpdateName(@RequestBody HeavyResourceAddressPartialUpdate partialUpdate) {
public ResponseEntity<?> partialUpdateName(@RequestBody HeavyResourceAddressOnly partialUpdate) {
heavyResourceRepository.save(partialUpdate);
return ResponseEntity.ok("resource address updated");
}
@RequestMapping(value = "/heavy/{id}", method = RequestMethod.PATCH, consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> partialUpdateGeneric(@RequestBody Map<String, Object> updates,
@PathVariable("id") String id) {
heavyResourceRepository.save(updates, id);
return ResponseEntity.ok("resource updated");
}
}

View File

@@ -0,0 +1,31 @@
package org.baeldung.web.dto;
public class HeavyResourceAddressOnly {
private Integer id;
private String address;
public HeavyResourceAddressOnly() {
}
public HeavyResourceAddressOnly(Integer id, String address) {
this.id = id;
this.address = address;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
}