Compare commits
No commits in common. "d9786fc6c8eee33ee77ffa0b56068e4779cd8f6c" and "3d997ef36eb08a16493da19fd83c931baad67407" have entirely different histories.
d9786fc6c8
...
3d997ef36e
|
|
@ -1,56 +0,0 @@
|
||||||
package com.ruoyi.common.core.utils;
|
|
||||||
|
|
||||||
import org.springframework.beans.BeanUtils;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 通用转换器基类
|
|
||||||
*
|
|
||||||
* @param <F> Source类型
|
|
||||||
* @param <T> Target类型
|
|
||||||
* @author ruoyi
|
|
||||||
*/
|
|
||||||
public abstract class BaseConvert<F, T> {
|
|
||||||
|
|
||||||
private final Class<F> sourceClass;
|
|
||||||
private final Class<T> targetClass;
|
|
||||||
|
|
||||||
protected BaseConvert(Class<F> sourceClass, Class<T> targetClass) {
|
|
||||||
this.sourceClass = sourceClass;
|
|
||||||
this.targetClass = targetClass;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected T innerFrom(F source) {
|
|
||||||
if (source == null) return null;
|
|
||||||
try {
|
|
||||||
T target = targetClass.getDeclaredConstructor().newInstance();
|
|
||||||
BeanUtils.copyProperties(source, target);
|
|
||||||
return target;
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected F innerTo(T target) {
|
|
||||||
if (target == null) return null;
|
|
||||||
try {
|
|
||||||
F source = sourceClass.getDeclaredConstructor().newInstance();
|
|
||||||
BeanUtils.copyProperties(target, source);
|
|
||||||
return source;
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected List<T> innerFromList(List<F> sourceList) {
|
|
||||||
if (sourceList == null) return null;
|
|
||||||
return sourceList.stream().map(this::innerFrom).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected List<F> innerToList(List<T> targetList) {
|
|
||||||
if (targetList == null) return null;
|
|
||||||
return targetList.stream().map(this::innerTo).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit e7a33e89a63a89b6ee4b661bd3a8d9bb893ee4d1
|
Subproject commit 12c7674d534677d43edc097ca08bcb792fe4ed6e
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit f42a12af0451cabd3e386f6491c3331eb1f29c96
|
Subproject commit 69af79b84290b26ce491dc8d9b658cb46b781060
|
||||||
Loading…
Reference in New Issue