Merge pull request #24 from hiparker/development

fix: 移除cglib
pull/33/head
Parker 3 years ago committed by GitHub
commit 08207adf9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -15,9 +15,9 @@
*/ */
package org.opsli.common.utils; package org.opsli.common.utils;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ObjectUtil;
import cn.hutool.extra.cglib.CglibUtil;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -35,54 +35,60 @@ import java.util.stream.Collectors;
@Slf4j @Slf4j
public final class WrapperUtil { public final class WrapperUtil {
/** 私有化构造函数 */ /**
private WrapperUtil(){} *
*/
private WrapperUtil() {
}
/** /**
* *
*
* @param source * @param source
* @param target * @param target
* @param <M> * @param <M>
* @return M * @return M
*/ */
public static <M> M transformInstance(Object source, Class<M> target){ public static <M> M transformInstance(Object source, Class<M> target) {
return transformInstance(source, target, false); return transformInstance(source, target, false);
} }
/** /**
* *
*
* @param source * @param source
* @param target * @param target
* @param <M> * @param <M>
* @return List<M> * @return List<M>
*/ */
public static <T,M> List<M> transformInstance(Collection<T> source, Class<M> target){ public static <T, M> List<M> transformInstance(Collection<T> source, Class<M> target) {
return transformInstance(source, target, false); return transformInstance(source, target, false);
} }
/** /**
* *
* @param source *
* @param target * @param source
* @param target
* @param isClone * @param isClone
* @return M * @return M
*/ */
public static <T,M> M transformInstance(Object source, Class<M> target, boolean isClone){ public static <T, M> M transformInstance(Object source, Class<M> target, boolean isClone) {
if(source == null){ if (source == null) {
return null; return null;
} }
if(isClone){ if (isClone) {
source = ObjectUtil.cloneIfPossible(source); source = ObjectUtil.cloneIfPossible(source);
} }
M m = null; M m = null;
try { try {
m = CglibUtil.copy(source, target); m = BeanUtil.copyProperties(source, target);
}catch (Exception e){ } catch (Exception e) {
log.error(e.getMessage(),e); log.error(e.getMessage(), e);
} }
return m; return m;
} }
@ -90,14 +96,15 @@ public final class WrapperUtil {
/** /**
* *
* @param source *
* @param target * @param source
* @param target
* @param isClone * @param isClone
* @param <M> M * @param <M> M
* @return List<M> * @return List<M>
*/ */
public static <T,M> List<M> transformInstance(Collection<T> source, Class<M> target, boolean isClone){ public static <T, M> List<M> transformInstance(Collection<T> source, Class<M> target, boolean isClone) {
if(CollUtil.isEmpty(source)){ if (CollUtil.isEmpty(source)) {
return Lists.newArrayList(); return Lists.newArrayList();
} }
@ -106,8 +113,8 @@ public final class WrapperUtil {
toInstanceList = source.stream() toInstanceList = source.stream()
.map((s) -> transformInstance(s, target, isClone)) .map((s) -> transformInstance(s, target, isClone))
.collect(Collectors.toList()); .collect(Collectors.toList());
}catch (Exception e){ } catch (Exception e) {
log.error(e.getMessage(),e); log.error(e.getMessage(), e);
} }
return toInstanceList; return toInstanceList;
} }

Loading…
Cancel
Save