英文:
While entering the jpql query using @Query i am not getting any output? Can someone tell me whats wrong with the below query?
问题
我正在使用以下查询语句:
@Query("from Flight where departureCity = :departureCity and arrivalCity = :arrivalCity and dateOfDeparture = :dateOfDeparture")
List<Flight> findFlights(@Param("departureCity") String departureCity, @Param("arrivalCity") String arrivalCity, @Param("dateOfDeparture") Date dateOfTravel);
当我使用默认的crud操作,如findAll,一切都正常显示,但是使用上面的查询语句时,没有显示任何内容。我不明白上面的查询语句是如何工作的,也不知道我犯了什么错误。请有人帮助我弄清楚这个问题。这是我在控制台上得到的输出:
Hibernate:select flight0_.id as id1_0_,flight0_.arrival_city as arrival_2_0_,flight0_.date_of_departure as date_of_3_0_,flight0_.departure_city as departur4_0_,flight0_.estimated_departure_time as estimate5_0_,flight0_.flight_number as flight_n6_0_,flight0_.operating_airlines as operatin7_0_ from flight flight0_ where flight0_.departure_city=? and flight0_.arrival_city=? and flight0_.date_of_departure=?
这是我的模型类:
private String flightNumber;
private String operatingAirlines;
private String departureCity;
private String arrivalCity;
private Date dateOfDeparture;
private Timestamp estimatedDepartureTime;
这是我的控制器类:
public String findflight(@RequestParam("departurecity") String departureCity, @RequestParam("arrivalcity") String arrivalCity,
@RequestParam("traveldate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date dateOfTravel, ModelMap model) {
List<Flight> flight = flightRepo.findFlights(departureCity, arrivalCity, dateOfTravel);
model.addAttribute("find", flight);
return "displayflights";
}
这是我的JSP页面:
<th>Airlines</th>
<th>Departure City</th>
<th>Arrival City</th>
<th>Departure Time</th>
</tr>
<c:forEach items="${find}" var="flight">
<tr>
<td>${flight.operatingAirlines}</td>
<td>${flight.departureCity}</td>
<td>${flight.arrivalCity}</td>
<td>${flight.estimatedDepartureTime}</td>
<td><a href="showCompleteReservation?Flightid=${flight.id}">select</a></td>
</tr>
英文:
I am using this query
@Query("from Flight where departureCity = :departureCity and arrivalCity =:arrivalCity and dateOfDeparture =:dateOfDeparture")
List<Flight> findFlights(@Param("departureCity") String departureCity,@Param("arrivalCity") String arrivalCity,@Param("dateOfDeparture") Date dateOfTravel);
When i use the default crud operations like findAll then everything is printing but with above query nothing is displayed. I dont understand how above query works and what mistake i am making. Someone please help me in getting this right..
This is the output i get on the console
Hibernate: select flight0_.id as id1_0_, flight0_.arrival_city as arrival_2_0_, flight0_.date_of_departure as date_of_3_0_, flight0_.departure_city as departur4_0_, flight0_.estimated_departure_time as estimate5_0_, flight0_.flight_number as flight_n6_0_, flight0_.operating_airlines as operatin7_0_ from flight flight0_ where flight0_.departure_city=? and flight0_.arrival_city=? and flight0_.date_of_departure=?
This is my MODEL CLASS
private String flightNumber;
private String operatingAirlines;
private String departureCity;
private String arrivalCity;
private Date dateOfDeparture;
private Timestamp estimatedDepartureTime;
This is my CONTROLLER CLASS
public String findflight(@RequestParam("departurecity")String departureCity, @RequestParam("arrivalcity")String arrivalCity,
@RequestParam("traveldate") @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) Date dateOfTravel, ModelMap model)
{
List<Flight> flight = flightRepo.findFlights(departureCity, arrivalCity, dateOfTravel);
model.addAttribute("find", flight);
return "displayflights";
}
This is my JSP PAGE
<th>Airlines</th>
<th>Departure City</th>
<th>Arrival City</th>
<th>Departure Time</th>
</tr>
<c:forEach items="${find}" var="flight">
<tr>
<td>${flight.operatingAirlines}</td>
<td>${flight.departureCity}</td>
<td>${flight.arrivalCity}</td>
<td>${flight.estimatedDepartureTime}</td>
<td><a href="showCompleteReservation?Flightid=${flight.id}">select</a></td>
</tr>
专注分享java语言的经验与见解,让所有开发者获益!
评论