遇到数组值参数绑定,但应为[java.lang.Integer(n/a)]


@Query("SELECT adv FROM Advocacyadv where (adv.patient.facilityId IN (:facilityIds) or :facilityIds is null) "
+ " order by adv.createdDate desc ")
public List<Advocacy> search(
@Param("facilityIds") Integer[] facilityIds);

上述代码给出以下错误

由以下原因引起:java.lang.IllegalArgumentException:遇到数组值参数绑定,但应为[java.lang.Integer(n/a(]

我的搜索可能有搜索参数,也可能没有。如果没有搜索参数,我希望显示所有数据。如果有搜索参数,我只需要那些匹配的。如何使用JPA实现这一点?

您需要使用一个列表

Query("SELECT adv FROM Advocacyadv where (adv.patient.facilityId IN (:facilityIds) or :facilityIds is null) "
+ " order by adv.createdDate desc ")
public List<Advocacy> search(
@Param("facilityIds") List<Integer> facilityIds);

更新:

正确的查询如下:
Query(
"SELECT adv FROM Advocacy adv " +
"WHERE (:facilityIds IS NULL OR adv.patient.facilityId IN :facilityIds) " +
"ORDER BY adv.createdDate DESC")
public List<Advocacy> search(@Param("facilityIds") List<Integer> facilityIds);
  1. 如果facilityId为空,它将返回所有Advocys
  2. 如果facilityId为空,它将返回一个空列表
  3. 否则,它将返回设施id中有id患者的所有Advocys

相关内容

  • 没有找到相关文章

最新更新