REST:如何使用PUT返回响应正文中的内容

时间:2014-09-11 16:51:13

标签: rest

我正在以这种方式实施PUT

@RequestMapping(method = RequestMethod.PUT, value = ServicesDictionary.API_DOMAIN_DEMAND + "/{id}", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(value = HttpStatus.OK, reason = "Update successful")
@ResponseBody
@Override
@LogMe("MarketDemandService.PUT.update")
public jsonObject update(@RequestBody @Valid MongoMarketDemand marketDemand, @PathVariable String id) {
    //do update
    return jsonObject
}

但是当我看到ResponseEntity时,我看到body是null。我怎样才能返回一个json对象?

1 个答案:

答案 0 :(得分:0)

在实体正文中返回一些内容......您可以使用@ResponseBody

public @ResponseBody MongoMarketDemand update(@RequestBody @Valid MongoMarketDemand marketDemand,     @PathVariable String id) {
   ...
   MongoMarketDemand updatedMarketDemand = ...
   return updatedMarketDemand;
}