@Override
public Page<Auth> getAllAuth(Integer pageNum, Integer pageSize) {
Sort sort = new Sort(Sort.Direction.ASC, "sort");
Pageable pageable = PageRequest.of(pageNum, pageSize, sort);
Specification<Auth> authSpecification = new Specification<Auth>() {
@Override
public Predicate toPredicate(Root<Auth> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
query.select(root.get("authID").get("authName").get("parentDataBase").get("onSqlTableName").get("authAddress").get("remark").get("authClassType"));/
/我想限制输出字段,如果不加这条是全部输出。加了这条报错 Illegal attempt to dereference path source [null.authID] of basic type; nested exception is java.lang.IllegalStateException: Illegal attempt to dereference path source [null.authID] of basic type
//另外如果我想在最终输出上增加一个自定义字段,有没有官方的方法可以用?谢谢各位帮忙
query.groupBy(root.get("parentAddr"));
query.where(cb.equal(root.get("authClassType").as(String.class), "1"));
query.orderBy(cb.desc(root.get("sort").as(Integer.class)));
return query.getGroupRestriction();
}
};
Page<Auth> page = authRepository.findAll(authSpecification, pageable);
System.err.println(page);
return page;
}