SpringMVC框架--@ResponseBody返回json格式对象

@Responsebody注解用于直接将方法返回值写入HTTP响应正文中,适用于异步数据获取场景。本文介绍如何配置环境解决No converter found for return value of type问题,并提供示例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

@Responsebody 的介绍

@Responsebody 注解表示该方法的返回的结果直接写入 HTTP 响应正文(ResponseBody)中,一般在异步获取数据时使用,通常是在使用 @RequestMapping 后,返回值通常解析为跳转路径,加上 @Responsebody 后返回结果不会被解析为跳转路径,而是直接写入HTTP 响应正文中。

@Responsebody 的使用及遇到的问题

 1.No converter found for return value of type

解决方案:缺少jar包


通过Maven导入jar包

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.9.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.5</version>
</dependency>

2.在使用@Responsebody时报错:Servlet.init() for servlet SpringDemo-dispatcher threw exception

解决方案:Jason相关jar包的版本问题,替换为新的版本

测试的代码

@RequestMapping(value = "/backJason")
@ResponseBody
public Student testJason(){
Student student = new Student();
student.setId("2");
student.setName("王");
student.setSex("男");
return student;
}
效果

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值