代码:
List<Long> followeeIdList = new ArrayList<>();
followeeIdList.add(12L);
followeeIdList.add(13L);
Specification<Moment> spec = (root, query, cb) -> {
Path<Object> bizId = root.get("bizId");
List<Predicate> list = new ArrayList<>();
CriteriaBuilder.In<Object> in = cb.in(bizId);
in.value(followeeIdList);
list.add(in);
Predicate[] array = new Predicate[list.size()];
return cb.and(list.toArray(array));
};
return CommonResult.success(momentRepository.findAll(spec));
成功运行的sql语句:
SELECT
moment0_.id AS id1_32_,
moment0_.CODE AS code2_32_,
moment0_.create_time AS create_t3_32_,
moment0_.del_tag AS del_tag4_32_,
moment0_.uid AS uid5_32_,
moment0_.update_time AS update_t6_32_,
moment0_.biz_id AS biz_id7_32_,
moment0_.biz_source AS biz_sour8_32_,
moment0_.content AS content9_32_,
moment0_.hot AS hot10_32_,
moment0_.STATUS AS status11_32_,
moment0_.title AS title12_32_,
moment0_.visible_flag AS visible13_32_
FROM
dm_moment moment0_
WHERE
moment0_.biz_id IN (?,
?)