@RequestMapping(method = RequestMethod.POST) @ResponseStatus(HttpStatus.CREATED) @ApiOperation(value = "create person", httpMethod = "POST") public void add(@RequestBody Person person, HttpServletResponse response) { log.info("create person {}", person); String location = ServletUriComponentsBuilder.fromCurrentRequest() .pathSegment("{id}") .buildAndExpand(person.getId()) .toUriString(); Person p = maps.putIfAbsent(person.getId(), person); response.setHeader("Location", location); }
@RequestMapping(value = "/{id}", method = RequestMethod.PUT) @ApiOperation( value = "update person", httpMethod = "PUT", consumes = "application/json,application/xml", produces = "application/json,application/xml") @ResponseStatus(HttpStatus.NO_CONTENT) public void update(@PathVariable Long id, @RequestBody Person person) { person.setId(id); maps.put(id, person); log.info("update person {}", person); }