我需要对某些实体使用一些庞大的查询。
@Repository
public interface MyRepository extends CrudRepository<Item, Long>
{
@Query(value = "select someDate as date,\n" +
" someInfo,\n" +
" max(someString) as someString,\n" +
" sum(someInt) as someInt,\n" +
......
......
)
Page<Item> findAllByDate(Date dateAfter, Date dateBefore, Pageable pageable);
}
代码看起来很糟糕。有没有一种方法可以从SQL文件或其他某种机制加载它们,以使其看起来合理且更易于维护?
理想情况是:
@Query(resource="my-query.sql")