🎉 init
This commit is contained in:
parent
7bb1ad5999
commit
3de333a1ce
@ -1,4 +0,0 @@
|
||||
package com.darkness.api.mapper.demo;
|
||||
|
||||
public class DemoMapper {
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
package com.darkness.api.mapper.test;
|
||||
|
||||
public interface TestMapper {
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
package com.darkness.api.repository.demo;
|
||||
|
||||
public interface DemoRepository {
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
package com.darkness.api.repository.test;
|
||||
|
||||
public interface TestRepository {
|
||||
}
|
36
src/main/java/com/darkness/common/util/ConvertUtils.java
Normal file
36
src/main/java/com/darkness/common/util/ConvertUtils.java
Normal file
@ -0,0 +1,36 @@
|
||||
package com.darkness.common.util;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class ConvertUtils {
|
||||
|
||||
public static <S, T> List<T> convertList(List<S> sourceList, Class<T> clazz) {
|
||||
if (CollectionUtils.isEmpty(sourceList)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<T> targetList = new ArrayList<>(sourceList.size());
|
||||
for (S sourceObj : sourceList) {
|
||||
if (Objects.nonNull(sourceObj)) {
|
||||
T targetObj = BeanUtils.instantiateClass(clazz);
|
||||
BeanUtils.copyProperties(sourceObj, targetObj);
|
||||
targetList.add(targetObj);
|
||||
} else {
|
||||
targetList.add(null); // 或者根据业务需求决定是否添加null
|
||||
}
|
||||
}
|
||||
return targetList;
|
||||
}
|
||||
public static <T, S> T convertObj(S sourceObj, Class<T> clazz) {
|
||||
if (Objects.isNull(sourceObj)) {
|
||||
return null;
|
||||
}
|
||||
T targetObj = BeanUtils.instantiateClass(clazz);
|
||||
BeanUtils.copyProperties(sourceObj, targetObj);
|
||||
return targetObj;
|
||||
}
|
||||
}
|
@ -5,13 +5,11 @@ import java.util.List;
|
||||
public class HandlePage {
|
||||
|
||||
/**分页 start = (page - 1) * size, end = page * size*/
|
||||
private <T> List<T> handlePage(List<T> source, int start, int end){
|
||||
int total = source.size();
|
||||
// end = end > total ? total : end;
|
||||
end = Math.min(end, total);
|
||||
if (end <= start) {
|
||||
return null;
|
||||
}
|
||||
return source.subList(start,end);
|
||||
public <T> List<T> handPage(List<T> data,int pageNum,int pageSize){
|
||||
|
||||
int fromIndex = Math.min((pageNum - 1) * pageSize, data.size());
|
||||
int toIndex = Math.min(fromIndex + pageSize, data.size());
|
||||
|
||||
return data.subList(fromIndex, toIndex);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user