com.codingapi.springboot.framework.dto.response.MultiResponse Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of springboot-starter Show documentation
Show all versions of springboot-starter Show documentation
springboot-starter project for Spring Boot
package com.codingapi.springboot.framework.dto.response;
import lombok.Getter;
import lombok.Setter;
import org.springframework.data.domain.Page;
import java.util.Collection;
/**
* @author lorne
* 2020/12/17
*/
@Setter
@Getter
public class MultiResponse extends Response {
private Content data;
public MultiResponse() {
this.data = new Content<>();
}
public static MultiResponse of(Collection data, long total) {
MultiResponse multiResponse = new MultiResponse<>();
multiResponse.setSuccess(true);
multiResponse.getData().setTotal(total);
multiResponse.getData().setList(data);
return multiResponse;
}
public static MultiResponse of(Page page) {
return of(page.getContent(), page.getTotalElements());
}
public static MultiResponse empty() {
MultiResponse multiResponse = new MultiResponse<>();
multiResponse.setSuccess(true);
return multiResponse;
}
public static MultiResponse of(Collection data) {
MultiResponse multiResponse = new MultiResponse<>();
multiResponse.setSuccess(true);
long total = 0;
if (data != null) {
total = data.size();
}
multiResponse.getData().setTotal(total);
multiResponse.getData().setList(data);
return multiResponse;
}
@Setter
@Getter
public static class Content {
private long total;
private Collection list;
}
}