问题描述
我想使用投影,以便为相同的查询返回较少的元素.
I want to use projections in order to return less elements for the same queries.
Page<Network> findByIdIn(List<Long> ids);
Page<NetworkSimple> findByIdIn(List<Long> ids);
由于查询是使用方法的名称创建的,因此我必须执行哪些选项来执行相同的查询但使用不同的名称?
Since the queries are created using the name of the method, what options do I have to do the same query but with different name ?
推荐答案
通过方法进行Spring数据查询是按照约定构造的,您不能更改名称但仍希望具有相同的行为.
Spring Data query via method is constructed by convention and you can't change the name and yet expecting a same behavior.
您可以尝试使用不依赖于方法名称的@Query批注,或者可以使用JPAQuery加上与表达式具有相同效果的FactoryExpression来实现自定义DAO.
You can try to use @Query annotations which doesn't depend on the method name, or possibly implementing custom DAO using JPAQuery plus FactoryExpression which has the same effect as projections.
这篇关于Spring Data中相同的查询方法和参数具有不同的返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!