Hibernate在where子句中处理空值

时间:2019-06-20 17:53:14

标签: java postgresql hibernate spring-boot

我有一个执行数据库查询的spring repo方法。传入的参数projectId有时可以为null。

这是我的查询:

@Query(value = "select p.id from project inner join class c on p.id = c.project_id where p.id = ?1",nativeQuery = true)
Set<Integer> test(Integer projectId);

我该如何处理?如果projectId为空,我想执行相同的查询,只是不使用where过滤器。因此,如果我有多个where表达式,我将删除具有null检查的表达式。

谢谢

0 个答案:

没有答案