67,549
社区成员




@Cacheable(cacheNames = "xqblog")
Page<XqBlog> findAll(Pageable pageable);
Page<XqBlog> objPage = xqBlogDao.findAll(new Specification<XqBlog>()
{
@Override
public Predicate toPredicate(Root<XqBlog> root,
CriteriaQuery<?> query, CriteriaBuilder criteriaBuilder)
{
List<Predicate> lstPredicates = new ArrayList<Predicate>();
String typeStr = typeId;
if(StringUtils.isNotBlank(typeStr))
{
request.getSession().setAttribute("nowTypeId", typeStr);
}
Object nowTypeIdObj = request.getSession().getAttribute("nowTypeId");
if(nowTypeIdObj != null)
{
typeStr = nowTypeIdObj+"";
}
// 是否根据文章标题进行条件查询
if (StringUtils.isNotBlank(search) && !search.equals("null") && !search.equals("undefined"))
{
request.setAttribute("search", search);
request.getSession().setAttribute("search", search);
lstPredicates.add(criteriaBuilder.like(root.get("title").as(String.class), "%" + search + "%"));
}
else
{
request.getSession().setAttribute("search", null);
}
if (typeStr!=null && !typeStr.equals("0"))
{
request.getSession().setAttribute("nowTypeId", typeStr);
//级联查询:使用root对象的join制定要关联的对象实体
Join<XqBlog, XqBlogType> join = root.join("blogType");
Path<String> exp3 = join.get("typeId");
lstPredicates.add(criteriaBuilder.equal(exp3, typeStr));
}
else
{
request.getSession().setAttribute("nowTypeId", 0);
}
Predicate[] arrayPredicates = new Predicate[lstPredicates.size()];
return criteriaBuilder.and(lstPredicates.toArray(arrayPredicates));
}
}, pageable);