返回ResponseEntity的JSON

我的控制器中有一个方法,应该以JSON返回String。它为非原始类型返回JSON:

@RequestMapping(value = "so", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)

ResponseEntity<String> so() {

return new ResponseEntity<String>("This is a String", HttpStatus.OK);

}

卷曲响应为:

This is a String

回答:

@RequestMapping(value = "so", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)

public @ResponseBody String so() {

return "This is a String";

}

以上是 返回ResponseEntity的JSON 的全部内容, 来源链接: utcz.com/qa/424532.html

回到顶部