能用VUE做网站,东莞市网站推广,网站开发需要学,全国新冠新增最新消息实际应用中需要在spring data jpa中使用原生sql#xff0c;传递的参数是list#xff0c;要根据list判断是否为空来判断是否要使用这个参数。
尝试了很多方法#xff0c;比如size、length、is null、!null等等#xff0c;都要报错#xff0c;比如could not extract Result…实际应用中需要在spring data jpa中使用原生sql传递的参数是list要根据list判断是否为空来判断是否要使用这个参数。
尝试了很多方法比如size、length、is null、!null等等都要报错比如could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.DataException: could not extract ResultSet 错误。
最后查阅网上文章使用如下方式得到了正确的结果。
Query(SELECT * FROM order \n WHERE (COALESCE(?1) IS NULL OR (id IN ?1)))
ListOrder getOrders(ListLong ids);这里的关键是COALESCE函数此函数表示传进去的list的值判断返回第一个不为null的值如果list为空则返回null。这样就相当于对list进行判断并执行id IN了。