Same query method and parameters with different return in Spring Data

五迷三道 提交于 2020-12-06 06:34:26

问题


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 ?


回答1:


Spring Data query via method is constructed by convention and you can't change the name and yet expecting a same behavior.

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.



来源:https://stackoverflow.com/questions/36548298/same-query-method-and-parameters-with-different-return-in-spring-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!