first commit

This commit is contained in:
starrySky
2024-03-20 09:28:04 +08:00
commit 989f0210f2
286 changed files with 25129 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
package com.starry.common.utils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
/**
* @author admin
*/
@Slf4j
public class ConvertUtil {
public static <T> T entityToVo(Object source, Class<T> target) {
if (source == null) {
return null;
}
T targetObject = null;
try {
targetObject = target.newInstance();
BeanUtils.copyProperties(source, targetObject);
} catch (Exception e) {
log.error("entityToVo error,source = {},target={}", source, target, e);
}
return targetObject;
}
public static <T> List<T> entityToVoList(Collection<?> sourceList, Class<T> target) {
if (sourceList == null) {
return null;
}
List<T> targetList = new ArrayList<>(sourceList.size());
try {
for (Object source : sourceList) {
T targetObject = target.newInstance();
BeanUtils.copyProperties(source, targetObject);
targetList.add(targetObject);
}
} catch (Exception e) {
log.error("entityToVo error,source = {},target={}", sourceList, target, e);
}
return targetList;
}
}