jpa 原生sql 【通过集合查询】
查询语法:
@Query(nativeQuery = true,value =
"select t1.*\n" +
"from table1 t1 left join table2 t2 on t1.id = t2.t_id \n" +
"where (COALESCE(?1) is null or (t2.id in ?1))",countProjection = "t1.id",
)
Page<Map<String, Object>> findBestNewByIds(Set<Long> exampleIds,PageRequest page);
通过集合查询语法 (COALESCE(?1) is null or (t2.id in ?1))
分页时会查询count总数,我们需要指定count字段 countProjection = “t1.id”,