com.quhaodian.data.rest.core.ConverUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of discover-hibernate-common Show documentation
Show all versions of discover-hibernate-common Show documentation
discover-hibernate_common is a lib for hibernate
package com.quhaodian.data.rest.core;
import com.quhaodian.data.core.Pagination;
import com.quhaodian.data.page.Page;
import com.quhaodian.data.rest.domain.AbstractPageVo;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
public class ConverUtils {
/**
* 从一个对象转换到例外一个对象
*
* @param result
* @param pager
*/
public static void cover(AbstractPageVo result, Pagination pager) {
result.setPage(pager.getPageNo());
result.setSize(pager.getPageSize());
result.setTotal(pager.getTotalCount());
result.setTotalPage(pager.getTotalPage());
}
public static void cover(AbstractPageVo result, Page pager) {
result.setPage(pager.getPageNumber());
result.setSize(pager.getPageSize());
result.setTotal((int) pager.getTotal());
result.setTotalPage(pager.getTotalPages());
}
public static AbstractPageVo coverpage(AbstractPageVo result, Pagination pager, Conver conver) {
cover(result, pager);
List vos = new ArrayList();
List cs = pager.getList();
if (cs != null) {
for (S classRoom : cs) {
vos.add(conver.conver(classRoom));
}
}
result.setList(vos);
return result;
}
public static AbstractPageVo coverPage(AbstractPageVo result, Page pager, Conver conver) {
cover(result, pager);
List vos = new ArrayList();
List cs = pager.getContent();
if (cs != null) {
for (S classRoom : cs) {
vos.add(conver.conver(classRoom));
}
}
result.setList(vos);
return result;
}
/**
* 转换集合功能
*
* @param source 转化源
* @param conver 转化器
* @return 转换后的集合
*/
public static List coverList(List source, Conver conver) {
List vos = new ArrayList();
if (source != null) {
for (S item : source) {
vos.add(conver.conver(item));
}
}
return vos;
}
public static List coverCollect(Collection source, Conver conver) {
List vos = new ArrayList();
if (source != null) {
for (S item : source) {
vos.add(conver.conver(item));
}
}
return vos;
}
}