将查询从2个参数更改为1个参数(年和月至YearMonth)

时间:2018-06-26 05:43:07

标签: java jpa spring-data-jpa spring-data

我想达到的目标是按yearMonth的方式获取(将参数的数量从2更改为单个)。

我现在所拥有的:

@Query("select p from Project p where MONTH(p.date) = :month and YEAR(p.date) = :year and p.user.id = :userId")
Page<Project> findAll(@Param("month") Integer month, @Param("year") Integer year, @Param("userId") Integer UserId, Pageable pageable);

我理想的解决方案可能看起来像这样:

@Query("select p from Project p where (...) and p.user.id = :userId")
Page<Project> findAll(@Param("yearMonth") YearMonth yearMonth, @Param("userId") Integer UserId, Pageable pageable);

Ofc我想从Date字段中获得thisyearMonth,如给定示例。 关于如何构造查询以使用yearMonth而不是year和month的任何想法?

0 个答案:

没有答案