[目录]
参考
相关项目
开发环境
名称 | 版本 |
---|---|
操作系统 | Windows 10 X64 |
JDK | JDK1.8(jdk-8u151-windows-x64) |
IntelliJ IDEA | IntelliJ IDEA 2018.3 |
Maven | Maven 3.6.0 |
mybatis-plus-boot-starter | 3.1.0 |
问题描述
错误提示
通过 FeignClient
调用微服务提供的分页对象 IPage<T>
报错
{
"timestamp": "2019-08-15T08:25:03.323+0000",
"status": 500,
"error": "Internal Server Error",
"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\"])",
"path": "/enta/api/Inv/Api/Test/Query"
}
相关代码
1.生产者
@Override
public ResponseVO<IPage<TRbtTestData>> Query(@RequestBody SuperEntity param){
Page<TRbtTestData> page = new Page<>();
page.setCurrent(1);
page.setSize(10);
return new ResponseVO<>(ResponseCode.OK, baseMapper.selectPageVO(page, param));
IPage<TRbtTestData> ipageData = baseMapper.selectPageVO(page, param);
}
2.Feign-api接口定义
@FeignClient(value = "service-producer")
public interface TRbtTestConsumer {
@PostMapping("/Test/Add")
ResponseVO<String> Add(@RequestBody TRbtTestData data);
@PostMapping("Test/Update")
ResponseVO<Boolean> Update(@RequestBody TRbtTestData data);
@RequestMapping(value="Test/Del",method=RequestMethod.GET)
ResponseVO<Boolean> Del(@RequestParam(value="name",required = true) String name,@RequestParam(value="version",required = true) String version);
@PostMapping("/Test/Get")
ResponseVO<TRbtTestData> Get(@RequestBody TRbtTestData data);
@PostMapping("/Test/Query")
ResponseVO<IPage<TRbtTestData>> Query(@RequestBody SuperEntity param);
}
3.消费者,Feign-api 调用
@PostMapping("/Test/Query")
@ApiOperation(value = "系统框架测试-获取分页数据", httpMethod = "POST", response = ResponseVO.class, notes = "系统框架测试-获取分页数据")
public ResponseVO Query(@RequestBody SuperEntity param){
return testConsumer.Query(param);
}
原因分析
当前 mybatis-plus
版本不支持 IPage
,使用 Page
即可
问题解决
1.生产者
@Override
public ResponseVO<Page<TRbtTestData>> Query(@RequestBody SuperEntity param){
Page<TRbtTestData> page = new Page<>();
page.setCurrent(1);
page.setSize(10);
//return new ResponseVO<>(ResponseCode.OK, baseMapper.selectPageVO(page, param));
IPage<TRbtTestData> ipageData = baseMapper.selectPageVO(page, param);
//IPage<TRbtTestData> 转换为 Page<TRbtTestData>
Page<TRbtTestData> pageData = new Page<>();
pageData.setRecords(ipageData.getRecords());
pageData.setCurrent(ipageData.getCurrent());
pageData.setSize(ipageData.getSize());
pageData.setTotal(ipageData.getTotal());
return new ResponseVO<>(ResponseCode.OK, pageData);
}
2.Feign-api接口定义
@FeignClient(value = "service-producer")
public interface TRbtTestConsumer {
@PostMapping("/Test/Add")
ResponseVO<String> Add(@RequestBody TRbtTestData data);
@PostMapping("Test/Update")
ResponseVO<Boolean> Update(@RequestBody TRbtTestData data);
@RequestMapping(value="Test/Del",method=RequestMethod.GET)
ResponseVO<Boolean> Del(@RequestParam(value="name",required = true) String name,@RequestParam(value="version",required = true) String version);
@PostMapping("/Test/Get")
ResponseVO<TRbtTestData> Get(@RequestBody TRbtTestData data);
@PostMapping("/Test/Query")
ResponseVO<Page<TRbtTestData>> Query(@RequestBody SuperEntity param);
}
3.消费者,Feign-api 调用
@PostMapping("/Test/Query")
@ApiOperation(value = "系统框架测试-获取分页数据", httpMethod = "POST", response = ResponseVO.class, notes = "系统框架测试-获取分页数据")
public ResponseVO Query(@RequestBody SuperEntity param){
return testConsumer.Query(param);
}