- feign调用jpa分页对象,返回值会报错,Page没有构造函数
解决
实现类-map
serviceimpl实现类,查询出Page,转换成Map,传输
new IG().trans(sysDept,current, size);
feign
feign调用,数据转成
new IG().trans(map);
1、自己定义了工具类
/**
* 转换分页
*/
@Data
public class IG<T> {
/**
* 分页转换成Map-传输-feign
*
* @param t page对象
* @param current 当前页
* @param size 当页条数
*/
public Map trans(org.springframework.data.domain.Page<T> t, int current, int size) {
Map map = new HashMap<>();
map.put("current", current);
map.put("size", size);
map.put("total", t.getTotalPages());
map.put("records", t.getContent());
return map;
}
/**
* 转换成page分页
*/
public IGQ<T> trans(Map map) {
/*页大小*/
Integer size = (Integer) map.get("size");
/*总条数*/
Integer total = (Integer) map.get("total");
/*当前页*/
Integer current = (Integer) map.get("current");
/*页面数据*/
List<T> records = (List<T>) map.get("records");
return new IGQ<>(records, total, size, current);
}
}
@Data
public class IGQ<T> {
private List<T> records;
private Integer total = 0;
private Integer size = 10;
private Integer current;
private boolean isSearchCount = true;
public IGQ(List<T> records, Integer total, Integer size, Integer current) {
this.records = records;
this.total = total;
this.size = size;
this.current = current;
}
}