通过FeignClient调用微服务提供的分页对象IPage报错的解决
作者:hu_xian_ 时间:2022-01-27 20:19:23
问题描述
通过FeignClient调用微服务提供的分页对象IPage报错
{
"message": "Type definition error: [simple type, class com.baomidou.mybatisplus.core.metadata.IPage]; nested exception is com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Cannot construct instance of `com.baomidou.mybatisplus.core.metadata.IPage` (no Creators, like default construct, exist): abstract types either need to be mapped to concrete types, have custom deserializer, or contain additional type information\n at [Source: (PushbackInputStream); line: 1, column: 37] (through reference chain: com.test.invoice.vo.ResponseVO[\"data\"])"
}
解决办法
当前mybatis-plus 本不支持 IPage,使用Page即可
生产者controller
Feign-api接口定义
消费者,Feign-api 调用
feign返回IPage无法返回结果集
通过feign调用,服务提供者返回IPage,客户端无法获取到结果;主要原因就是jackson需要默认构造函数序列化;
@PostMapping(value ="/page",consumes = MediaType.APPLICATION_JSON_VALUE)
ResponseModel<IPage<CommentDTO>> loadCommentPage(@RequestBody Comment condition);
Mybatis-plus修改方式
IPage改成Page即可
spring-data 修改方式也是一样的,最简单就是自己实现IPage就可以了,也可以通过SpringMvcContract方式重造结果集
feign的几种可能性
1、接口直接被调用
2、接口直接被调用的同时其他模块也需要这个接口,那么其他模块就需要通过fegin调用
3、不会被直接调用,所有接口通过feign调用
基于以上三点,有如下可能性
1、在使用fegin时候,服务提供者到底应该直接返回ResponseModel(统一返回值)还是只返回结果?
1和3直接返回ResponseModel即可,2如果直接返回ResponseModel那么调用者就需要自己判断code或者直接返回给前段不做任何处理,如果直接返回结果那么直接被调用那个接口就无法统一返回值;建议直接写成俩个方法
来源:https://blog.csdn.net/hu_xian_/article/details/103961149
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Swing常用组件之多行文本区JTextArea
SpringBoot如何返回Json数据格式
![](https://img.aspxhome.com/file/2023/0/61390_0s.png)
Java求一个分数数列的前20项之和的实现代码
Spring Cloud Config实现分布式配置中心
C语言实现自定义扫雷游戏(递归版)
![](https://img.aspxhome.com/file/2023/2/107382_0s.jpg)
Java设计模式之抽象工厂模式实例详解
![](https://img.aspxhome.com/file/2023/1/60341_0s.png)
flutter实现appbar下选项卡切换
![](https://img.aspxhome.com/file/2023/3/87313_0s.gif)
Java ConcurrentHashMap的源码分析详解
![](https://img.aspxhome.com/file/2023/1/62121_0s.png)
Java设计模式之工厂模式案例详解
![](https://img.aspxhome.com/file/2023/2/60342_0s.png)
图解Java线程的生命周期
![](https://img.aspxhome.com/file/2023/2/60822_0s.png)
Springboot与vue实现文件导入方法具体介绍
![](https://img.aspxhome.com/file/2023/8/58738_0s.png)
简单了解Java多态向上转型相关原理
Android 6.0动态权限申请教程
JavaApi实现更新删除及读取节点
![](https://img.aspxhome.com/file/2023/7/59037_0s.png)
java模拟hibernate一级缓存示例分享
SpringBoot v2.2以上重复读取Request Body内容的解决方案
java集合Collection实现类解析ArrayList LinkedList及Vector
![](https://img.aspxhome.com/file/2023/6/61956_0s.png)
java springmvc实现验证码功能
![](https://img.aspxhome.com/file/2023/1/61781_0s.jpg)