ResponseBody ResponseEntity boolean类型获取失败

javaBena中的boolean类型的isName字段,

1 如果使用通用mapper的查数据库,控制台可以看到字段的false|ture,返回前端如果使用ResponseBody|ResponseEntity则可能存在前端获取的json缺少该字段。为什么是可能,因为我刚开始运行好几次没问题,用着用着就出现前端没有该字段,原因未知。如果使用Jackson序列化或者字符串就没有在这个问题

2 如果使用mybatis的注解或xml查询,前端能得到该字段,但是字段会缺少is,变为name,

3 如果不查数据库,单定义包含这种字段的对象,浏览器可以正常获取,也不缺少不少is

建议:功底不足,少使用isName这种方式,容易采坑

如果非要使用,可以参考https://blog.csdn.net/u011646880/article/details/79159533

在 Java 中,你可以使用 HttpClient 发送请求并获得一个 HttpEntity 对象,如果你想将它转换为 ResponseEntity 对象,可以参考以下代码示例: ```java import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.ContentType; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import org.springframework.http.ResponseEntity; import java.io.IOException; class Program { public static void main(String[] args) throws IOException { String url = "https://example.com"; HttpClient client = HttpClients.createDefault(); HttpPost request = new HttpPost(url); // 设置请求体 String requestBody = "{\"key\":\"value\"}"; StringEntity entity = new StringEntity(requestBody, ContentType.APPLICATION_JSON); request.setEntity(entity); // 发送请求并获取响应 HttpResponse response = client.execute(request); // 将 HttpEntity 转换为 ResponseEntity HttpEntity responseEntity = response.getEntity(); String responseBody = EntityUtils.toString(responseEntity); int statusCode = response.getStatusLine().getStatusCode(); ResponseEntity<String> responseEntity = ResponseEntity.status(statusCode).body(responseBody); // 处理响应 System.out.println("Response Body: " + responseEntity.getBody()); } } ``` 在上述示例中,我们使用 Apache HttpClient 发送 POST 请求,并将请求体设置为 JSON 字符串。然后,我们执行请求并获取响应。 接下来,我们将响应中的 HttpEntity 对象转换为 ResponseEntity。首先,我们使用 EntityUtils 类将 HttpEntity 转换为字符串形式的响应体。然后,我们通过获取响应的状态码,并使用 ResponseEntity.status() 和 .body() 方法创建 ResponseEntity 对象。 最后,我们可以根据需要处理 ResponseEntity 中的响应数据。 请注意,这里示例中使用的是 Apache HttpClient,而不是 Spring 的 WebClient。如果你使用的是 Spring WebClient,请使用 WebClient 的相关方法来发送请求和处理响应。 希望对你有所帮助,如果有任何问题,请随时提问。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值