コード例 #1
0
  /**
   * Web service endpoint to create a single 'SimpleObject' entity. The HTTP request body is
   * expected to contain a entity in JSON format.
   *
   * <p>If created successfully, the persisted 'SimpleObject' is returned as JSON with HTTP status
   * 201.
   *
   * <p>If not created successfully, the service returns an empty response body with HTTP status
   * 500.
   *
   * @param simpleObject The object to be created.
   * @return A ResponseEntity containing a single object, if created successfully, and a HTTP status
   *     code as described in the method comment.
   * @throws Exception Thrown if a problem occurs completing the request.
   */
  @RequestMapping(
      value = "/tutorial/simple",
      method = RequestMethod.POST,
      consumes = MediaType.APPLICATION_JSON_VALUE,
      produces = MediaType.APPLICATION_JSON_VALUE)
  public ResponseEntity<SimpleObject> createSimpleObject(@RequestBody SimpleObject simpleObject) {

    SimpleObject savedSimpleObject = simpleObjectMap.put(simpleObject.getId(), simpleObject);
    return new ResponseEntity<>(savedSimpleObject, HttpStatus.CREATED);
  }
コード例 #2
0
  /**
   * Web service endpoint to update a single 'SimpleObject' entity. The HTTP request body is
   * expected to contain a 'SimpleObject' in JSON format. The object is updated in the data
   * repository.
   *
   * <p>If updated successfully, the persisted Greeting is returned as JSON with HTTP status 200.
   *
   * <p>If not found, the service returns an empty response body and HTTP status 404.
   *
   * <p>If not updated successfully, the service returns an empty response body with HTTP status
   * 500.
   *
   * @param simpleObject The SimpleObject to be updated.
   * @return A ResponseEntity containing a single SimpleObject, if updated successfully, and a HTTP
   *     status code as described in the method comment.
   * @throws Exception Thrown if a problem occurs completing the request.
   */
  @RequestMapping(
      value = "/tutorial/simple/{id}",
      method = RequestMethod.PUT,
      consumes = MediaType.APPLICATION_JSON_VALUE,
      produces = MediaType.APPLICATION_JSON_VALUE)
  public ResponseEntity<SimpleObject> updateSimpleObject(@RequestBody SimpleObject simpleObject) {

    SimpleObject savedSimpleObject = simpleObjectMap.replace(simpleObject.getId(), simpleObject);
    return new ResponseEntity<>(savedSimpleObject, HttpStatus.OK);
  }