在JPA实现JpaSpecificationExecutor接口一个方法时
pageable =PageRequest.of(dataQueryObjectpage.getPageNum(), dataQueryObjectpage.getPageSize(), new Sort(new Order(dataQueryObjectpage.isAscending() ? Direction.ASC : Direction.DESC, dataQueryObjectpage.getPropertyName())));
提示:The constructor Sort(Sort.Order...) is deprecated
查看Sort的原码可以看到:public Sort(Order... orders)已经过时
public class Sort implements Streamable<org.springframework.data.domain.Sort.Order>, Serializable {
/**
* Creates a new {@link Sort} instance using the given {@link Order}s.
*
* @param orders must not be {@literal null}.
*/
@Deprecated
public Sort(Order... orders) {
this(Arrays.asList(orders));
}
/**
* Creates a new {@link Sort} instance.
*
* @param direction defaults to {@link Sort#DEFAULT_DIRECTION} (for {@literal null} cases, too)
* @param properties must not be {@literal null}, empty or contain {@literal null} or empty strings.
*/
public Sort(Direction direction, String... properties) {
this(direction, properties == null ? new ArrayList<>() : Arrays.asList(properties));
}
}
根据我以上的方法可以更改为:
pageable =PageRequest.of(dataQueryObjectpage.getPageNum(), dataQueryObjectpage.getPageSize(), Sort.by(dataQueryObjectpage.isAscending() ? Direction.ASC : Direction.DESC,dataQueryObjectpage.getPropertyName()));