Код: Выделить всё
public class Revenue {
... (Other fields omitted for simplicity)
@Column(name = "transaction_date")
private LocalDate transactionDate;
Можно ли сделать это с помощью готовых методов запроса JPA?
Я пробовал следующее:
Код: Выделить всё
@Repository
public interface RevenueRepository extends JpaRepository {
@Query(
"SELECT r FROM revenue WHERE YEAR(r.transactionDate) = :year AND MONTH(r.transactionDate) = :month")
Page findByYearAndMonth(
@Param("year") int year, @Param("month") int month, Pageable pageable);
...
public interface RevenueService {
Page getByYearAndMonth(int year, int month, Pageable pageable);
...
@Service
public class RevenueServiceImpl implements RevenueService {
@Autowired private RevenueRepository revenueRepository;
@Override
public Page getByYearAndMonth(int year, int month, Pageable pageable) {
return revenueRepository.findByYearAndMonth(year, month, pageable).map(RevenueDTOResponse::new);
}
...
@GetMapping("/{year}/{month}")
public ResponseEntity
> getByYearAndMonth(
@PathVariable int year, int month, Pageable pageable) {
return new ResponseEntity(
revenueService.getByYearAndMonth(year, month, pageable), HttpStatus.OK);
}
Подробнее здесь: https://stackoverflow.com/questions/787 ... -arguments