ResponseBody转换为json
时间: 2023-08-16 14:17:14 浏览: 147
@ResponseBody注解可以将方法的返回结果转换为JSON格式返回给前端。在Spring MVC中,当遇到@ResponseBody注解时,处理器会将该方法的响应类型标记为JSON数据集。在执行完控制器方法后,处理器会使用结果解析器(ResultResolver)去解析返回结果。解析器会轮询注册给Spring MVC的HttpMessageConverter接口的实现类,其中包括MappingJackson2HttpMessageConverter。如果找到匹配的转换器,它会将结果转换为JSON格式。如果找不到匹配的转换器,Spring MVC会继续处理后续流程。如果控制器的返回结果被MappingJackson2HttpMessageConverter转换,后续的模型和视图(ModelAndView)将返回null,视图解析器和视图渲染将不再执行。\[3\]
#### 引用[.reference_title]
- *1* [39、HttpMessageConverter的@ReponseBody处理json(转换为json字符串(浏览器才能识别))](https://blog.csdn.net/logtcm4/article/details/126912007)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *2* [Java中@ResponseBody直接转换json](https://blog.csdn.net/weixin_42372731/article/details/114154320)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item]
- *3* [【@ResponseBody注解如何将对象转换为json返回的】](https://blog.csdn.net/li646495946/article/details/124180924)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文