英文:
Use JPA query methods to seach records for specific day (day and month)
问题
我正在尝试为一个具有电影记录和发布日期的数据库实现一个RESTful API的搜索操作。数据库的格式类似于这样:
标题 播放时长 语言 发布日期
Traffic shop 104 en 12/15/1995
Nocturnal men 101 en 12/22/1995
Exit front 127 en 12/22/1996
The last paradise 106 en 02/10/1995
我需要获取所有在特定日期,比如说"12/22"发布的电影,所以它需要返回:
Nocturnal men 101 en 12/22/1995
Exit front 127 en 12/22/1996
即使它们发布在不同的年份也可以。我不确定是否可以使用JPA中的查询方法来实现这个,但我仍在学习中。
英文:
I'm trying to implement a search operation for a restful API on a databases with records of movies with release dates. The format of the database is something like this:
title running time language release date
Traffic shop 104 en 12/15/1995
Nocturnal men 101 en 12/22/1995
Exit front 127 en 12/22/1996
The last paradise 106 en 02/10/1995
, i need to get all movies released during lets say "12/22", so it needs to return:
Nocturnal men 101 en 12/22/1995
Exit front 127 en 12/22/1996
, even if they have been released in two different years. I'm not sure if this can be done using query methods in JPA but i'm still learning.
答案1
得分: 1
You can use day()
and month()
functions to extract data from the date for comparison.
@Query("SELECT m from Movie m WHERE day(m.releaseDate) = ?1 and month(m.releaseDate) = ?2")
List<Movie> getMovieByDayAndMonth(int day, int month);
英文:
You can use day()
and month()
function to extract data from date to compare
@Query("SELECT m from Movie m WHERE day(m.releaseDate) = ?1 and month(m.releaseDate) = ?2")
List<Movie> getMovieByDayAndMonth(int day, int month);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论