0

我正在调用findall()JpaRepository 的方法如下

服务

on.findall(specificationsbuilder.getspecifications(params), paegable obj)  

specificationsbuilder.getspecifications(param)

退货规格

我的问题是,如果规范为空,我将 findall(specifications,paegable) 工作

4

2 回答 2

3

根据SimpleJpaRepository的源代码,它应该可以工作,因为@Nullable 说它会接受 null:

@Override
    public Page<T> findAll(@Nullable Specification<T> spec, Pageable pageable) {

        TypedQuery<T> query = getQuery(spec, pageable);
        return isUnpaged(pageable) ? new PageImpl<T>(query.getResultList())
                : readPage(query, getDomainClass(), pageable, spec);
}
于 2018-11-22T14:27:22.750 回答
1

在这里阅读:https ://jira.spring.io/browse/DATAJPA-121 ,截至最新的spring数据jpa,如果您的参数为null,查询将自动形成为null。

另外,从 Spring data jpa 2.0 开始,spring 现在支持 @Nullable 注解。这有助于处理传递的空参数。

@Nullable – 用于可以为 null 的参数或返回值。

如果值为 null,它将自动返回 true,如果不为 null,它将在表中搜索该值。

于 2018-11-22T14:25:07.653 回答