gpt4 book ai didi

spring-mvc - 返回JSON作为ResponseEntity

转载 作者:行者123 更新时间:2023-12-03 12:02:41 30 4
gpt4 key购买 nike

我的 Controller 中有一个方法应该以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);
}

curl 响应为:
This is a String

最佳答案

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

关于spring-mvc - 返回JSON作为ResponseEntity <String>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18385361/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com