diff --git a/starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/base/BaseServiceExtImpl.java b/starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/base/BaseServiceExtImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..c3b5d1cc4c230edfc4a620482d7b2d27b32d166b --- /dev/null +++ b/starters/mybatis-spring-boot-starter/src/main/java/com/schbrain/framework/autoconfigure/mybatis/base/BaseServiceExtImpl.java @@ -0,0 +1,37 @@ +package com.schbrain.framework.autoconfigure.mybatis.base; + +import com.schbrain.common.util.BeanCopyUtils; +import org.springframework.core.ResolvableType; + +import java.util.List; + +/** + * @author liaozan + * @since 2023/7/7 + */ +public class BaseServiceExtImpl, Source extends BaseEntity, Target> extends BaseServiceImpl { + + protected final Class targetType; + + public BaseServiceExtImpl() { + // noinspection unchecked + this.targetType = (Class) ResolvableType.forInstance(this).getSuperType().getGeneric(2).getRawClass(); + } + + protected Target toTarget(Source entity) { + return BeanCopyUtils.copy(entity, targetType); + } + + protected List toTargetList(List entityList) { + return BeanCopyUtils.copyList(entityList, targetType); + } + + protected Source fromTarget(Target target) { + return BeanCopyUtils.copy(target, entityClass); + } + + protected List fromTargetList(List targetList) { + return BeanCopyUtils.copyList(targetList, entityClass); + } + +}