我正在尝试使用Spring Boot JPA从MySQL表中检索所有记录。以下是存储库定义

MovieRepository类

@Query("From MovieEntity m, TheaterMovieShowEntity tms, TheaterEntity t where t.city=?1 and t.theaterid=tms.theaterid and m.movieid=tms.movieid and t.seatsavailable>=?2")
    List<Movie> getMoviesDetails(String cityName, int noOfTickets)throws MovieException;


MovieService类

public List<Movie> getMoviesDetails(String cityName, int noOfTickets)throws MovieException{
        List<Movie>moviesIntheCityList = new ArrayList<Movie>();
        **moviesIntheCityList = (List<Movie>) movieRepository.getMoviesDetails(cityName, noOfTickets);**
        System.out.println("in the getMoviesDetails after querying"+moviesIntheCityList); // This is null
        return moviesIntheCityList;
    }


我想念什么?

最佳答案

在您的存储库文件中使用这种方式

List<Movie> findByCityNameAndNoOfTickets(String cityName, int noOfTickets)

参考Query Creation

09-28 03:46