fix: 无查询条件查询数据
parent
659336ab85
commit
fe7bf483c2
|
@ -5,13 +5,17 @@ import cc.iotkit.common.api.Paging;
|
|||
import cc.iotkit.common.utils.MapstructUtils;
|
||||
import cc.iotkit.data.ICommonData;
|
||||
import cc.iotkit.data.util.PageBuilder;
|
||||
import cc.iotkit.data.util.PredicateBuilder;
|
||||
import cc.iotkit.model.Id;
|
||||
import com.querydsl.core.types.Predicate;
|
||||
import org.springframework.data.domain.Example;
|
||||
import org.springframework.data.domain.ExampleMatcher;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
|
@ -79,8 +83,12 @@ public interface IJPACommData< T extends Id<ID>, ID> extends ICommonData<T , ID
|
|||
@Override
|
||||
default Paging<T> findAll(PageRequest<T> pageRequest) {
|
||||
Example example = genExample(pageRequest.getData());
|
||||
|
||||
Page<T> all = getBaseRepository().findAll(example, PageBuilder.toPageable(pageRequest));
|
||||
Page<T> all = null;
|
||||
if(Objects.isNull(example)){
|
||||
all = getBaseRepository().findAll(PageBuilder.toPageable(pageRequest));
|
||||
}else{
|
||||
all =getBaseRepository().findAll(example, PageBuilder.toPageable(pageRequest));
|
||||
}
|
||||
return PageBuilder.toPaging(all, getTClass());
|
||||
}
|
||||
|
||||
|
@ -90,8 +98,14 @@ public interface IJPACommData< T extends Id<ID>, ID> extends ICommonData<T , ID
|
|||
@Override
|
||||
default List<T> findAllByCondition(T data) {
|
||||
Example example = genExample(data);
|
||||
List all = null;
|
||||
if(Objects.isNull(example)){
|
||||
all = getBaseRepository().findAll();
|
||||
|
||||
List all = getBaseRepository().findAll(example);
|
||||
}else{
|
||||
all = getBaseRepository().findAll(example);
|
||||
|
||||
}
|
||||
return MapstructUtils.convert(all, getTClass());
|
||||
}
|
||||
|
||||
|
@ -111,6 +125,9 @@ public interface IJPACommData< T extends Id<ID>, ID> extends ICommonData<T , ID
|
|||
|
||||
|
||||
default Example genExample(T data) {
|
||||
if(Objects.isNull(data)){
|
||||
return null;
|
||||
}
|
||||
return Example.of(MapstructUtils.convert(data, getJpaRepositoryClass()));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue