我正在使用io.swagger.annotations
与控制器一起使用,注释将帮助我生成api文档。
我有一个方法listPriceCompetitivenessDetail
,其结果类型为ResultDTO<Pager<CompetitivenessVO>>
,但是文档仅显示了ResultDTO
和Pager
,看来他无法识别{{1 }},因为CompetitivenessVO
现在位于第三层的通用结构之内。
有人想解决这个问题吗?
CompetitivenessVO
@Data
@ApiModel("响应实体")
public class ResultDTO<T>
{
@ApiModelProperty("请求成功标识")
private Boolean success;
@ApiModelProperty(value = "响应消息码 0-成功 300-失败",example = "0")
private Integer code;
@ApiModelProperty("响应消息")
private String msg;
@ApiModelProperty("响应数据")
private T data;
public ResultDTO(){}
public static <T> ResultDTO<T> newSuccessBean(){
ResultDTO resultDTO = new ResultDTO();
resultDTO.setSuccess(true);
resultDTO.setMsg(MessageCode.SUCCESS_MESSAGE);
return resultDTO;
}
public static <T> ResultDTO newSuccessBean(T data){
ResultDTO resultDTO = newSuccessBean();
resultDTO.setData(data);
return resultDTO;
}
public static <T> ResultDTO<T> newFailureBean(String msg){
ResultDTO resultDTO = new ResultDTO();
resultDTO.setSuccess(false);
resultDTO.setMsg(msg);
return resultDTO;
}
}
/**
*
* @type Pager
* @description 分页器
* @param
* @author qianye.zheng
*/
@ApiModel("分页器")
public class Pager<T>
{
public Pager(){}
public Pager(List<T> beanList, long dataSize,int currentPage,int pageSize){
this.beanList = beanList;
this.dataSize = dataSize;
this.currentPage = currentPage;
this.pageSize = pageSize;
}
/**
*
* @description 构造方法
* @param beanList
* @param dataSize
* @param pageSize
* @author qianye.zheng
*/
public Pager(final List<T> beanList, final long dataSize, final int pageSize)
{
this.beanList = beanList;
this.dataSize = dataSize;
this.pageSize = pageSize;
}
public Pager(int dataSize,List<T> beanList,BaseQuery query){
this(beanList,dataSize,query.getCurrentPage(),query.getPageSize());
}
public static final Integer DEFAULT_PAGE_SIZE = 20;
@ApiModelProperty(value = "页_大小", required = true, example = "20")
private Integer pageSize = DEFAULT_PAGE_SIZE;
@ApiModelProperty(value = "当前页,从1开始", required = true, example = "1")
private Integer currentPage = 1;
@ApiModelProperty(value = "记录总条数", required = false, example = "0")
private long dataSize = 0;
@ApiModelProperty(value = "总页数", required = false, example = "0")
private long totalPage;
@ApiModelProperty(value = "是否要分页,默认为true")
private boolean needPage = true;
@ApiModelProperty(value = "分页数据")
private List<T> beanList;
/**
* @return the pageSize
*/
public Integer getPageSize() {
if (pageSize <= 0)
{
pageSize = DEFAULT_PAGE_SIZE;
}
return pageSize;
}
/**
* @param pageSize the pageSize to set
*/
public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
}
/**
* @return the currentPage
*/
public Integer getCurrentPage() {
return currentPage;
}
/**
* @param currentPage the currentPage to set
*/
public void setCurrentPage(Integer currentPage) {
this.currentPage = currentPage;
}
/**
* @return the dataSize
*/
public long getDataSize() {
return dataSize;
}
/**
* @param dataSize the dataSize to set
*/
public void setDataSize(long dataSize) {
this.dataSize = dataSize;
}
/**
* @return the needPage
*/
public boolean isNeedPage() {
return needPage;
}
/**
* @param needPage the needPage to set
*/
public void setNeedPage(boolean needPage) {
this.needPage = needPage;
}
/**
* @return the beanList
*/
public Object getBeanList() {
return beanList;
}
/**
* @param beanList the beanList to set
*/
public void setBeanList(List<T> beanList) {
this.beanList = beanList;
}
/**
*
* @description
* @return
* @author qianye.zheng
*/
public int getOffset()
{
if (currentPage == 0)
return 0;
return (currentPage - 1) * pageSize;
}
/**
*
* @description 总页数
* @return
* @author qianye.zheng
*/
public long getTotalPage()
{
if (getDataSize() == 0)
{
totalPage = 0;
} else if (getDataSize() <= getPageSize())
{ // 没有超过1页
totalPage = 1;
} else
{
totalPage = getDataSize() / getPageSize();
if (getDataSize() % getPageSize() != 0)
{
// 还有下一页,加1
totalPage += 1;
}
}
return totalPage;
}
public Pager<T> withPageSize(int pageSize){
this.pageSize = pageSize;
return this;
}
public Pager<T> withCurrentPage(int currentPage){
this.currentPage = currentPage;
return this;
}
public Pager<T> withBeanList(List<T> beanList){
this.beanList = beanList;
return this;
}
}
现在的实际结果是:
@Data
@ToString
@ApiModel(description = "竞争力展示实体")
public class CompetitivenessVO {
@ApiModelProperty("日期")
private LocalDate date;
@ApiModelProperty("区域")
private String area;
@ApiModelProperty("区域主键ID")
private Integer areaId;
@ApiModelProperty("beat产品数")
private Integer merchandiseQuantityOfBeat;
@ApiModelProperty("meet产品数")
private Integer merchandiseQuantityOfMeet;
@ApiModelProperty("lose产品数")
private Integer merchandiseQuantityOfLose;
@ApiModelProperty("总产品数")
private Integer merchandiseQuantityOfTotal;
@ApiModelProperty("beat率")
private Double rateOfBeat;
@ApiModelProperty("beat率上升")
private Boolean rateOfBeatHasRisen;
@ApiModelProperty("meet率")
private Double rateOfMeet;
@ApiModelProperty("lose率")
private Double rateOfLose;
@ApiModelProperty("lose率上升")
private Boolean rateOfLoseHasRisen;
@ApiModelProperty("匹配产品总数")
private Integer matchingMerchandiseCount;
@ApiModelProperty("匹配酒店总数")
private Integer matchingHotelCount;
}
我期望的是:
{
"code": 0,
"data": {
"beanList": {},
"currentPage": 1,
"dataSize": 0,
"needPage": true,
"offset": 0,
"pageSize": 20,
"totalPage": 0
},
"msg": "string",
"success": true
}