我通过遵循一些教程来从事Spring Boot项目。我无法解决上述问题,我尝试了一切。请帮我
Bean类
@Entity
@Table(name="flight")
public class Flight {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private long id;
@Column(name = "Flight_Number")
private String flightNumber;
@Column(name = "Operating_Airlines")
private String operatingAirlines;
@Column(name = "Departure_City")
private String departureCity;
@Column(name = "Arrival_city")
private String arrivalCity;
@Column(name = "Date_Of_Departure")
private Date dateOfDeparture;
@Column(name = "Estimated_Departure_Time")
private Timestamp estimatedDepartureTime;
//getters and setters
}}
存储库
public interface FlightRepository extends JpaRepository<Flight, Long> {
@Query(value = "select * from flight f where f.departureCity =:departureCity and f.arrivalCity =:arrivalCity and f.dateOfDeparture =:dateOfDeparture ", nativeQuery = true)
List<Flight> findFlights(@Param("departureCity") String from, @Param("arrivalCity") String to,
@Param("dateOfDeparture") Date departureDate);
}
数据库
create table flight
(
Id int not null auto_increment,
Flight_Number varchar(20) not null,
Operating_Airlines varchar(20) not null,
Departure_City varchar(20) not null,
Arrival_city varchar(20) not null,
Date_Of_Departure date not null,
Estimated_Departure_Time timestamp default current_timestamp,
primary key (Id)
)
我在“ where子句”中得到了“ f.departureCity”未知列。
答案 0 :(得分:2)
在这种情况下,您应该像将查询直接写入数据库一样编写查询,因为@Query标记为本机。因此,请参考脚本中定义的字段以创建表。
'f.Departure_City'
而不是'f.departureCity'
,依此类推...
答案 1 :(得分:-2)
我认为您必须更改查询中的文件名并再次执行
因此将 dateOfDeparture
更改为 Date_Of_Departure
就可以了