jpa规格和定制选择

时间:2019-01-21 15:02:23

标签: jpa spring-data-jpa

在我看来,specification在搜索条件不同的情况下功能强大,因此基本上解决了SQL where子句之后的复杂性。 selectwhere之间的sql子句怎么样?例如,是否可以使用规范来实现以下两个JPQL:

"select new b.C(a.type, count(a.id)) from A a where a.some_id =: someId and a.create_time between :startT and :stopT group by a.type"
List<C> function1(...) 

未分配搜索时间时,前一条语句变为:

"select new b.C(a.type, count(a.id)) from A a where a.some_id =: someId group by a.type"
List<C> function2(...)

if (startT == null && stopT == null) function1();
else function2();

搜索条件越多,功能越多。到目前为止,我已经看到specification返回List<TheEntity>或Long从JpaSpecificationExecutor开始计数,我想知道它是否可以用于返回自定义结果。

0 个答案:

没有答案