一尘不染

返回ResponseEntity的JSON

spring-mvc

我的控制器中有一个方法,应该以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

阅读 720

收藏
2020-06-01

共1个答案

一尘不染

@RequestMapping(value = "so", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public @ResponseBody String so() {
    return "This is a String";
}
2020-06-01