[英]How to get the ID of linked table in JPA repository
I have the following code in which I want to get the id of rider, But I have no idea how to do this , Actually rider is the type of User which is linked to RiderLocation
table , When I change the type of rider to User then I cant send the id in parameter of URL like this 我有以下代码,我想获取骑手的ID,但是我不知道该怎么做,实际上骑手是链接到
RiderLocation
表的User类型,当我将骑手的类型更改为User时,我无法像这样在URL参数中发送ID
http://localhost:3000/api/riderLocations/search/findByRider?rider_id=3 HTTP://本地主机:3000 / API / riderLocations /搜索/ findByRider rider_id = 3
Code is below 代码如下
RiderLocation.java RiderLocation.java
@Entity
public class RiderLocation implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@ManyToOne
private User rider;
private Double latitude;
private Double longitude;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public User getRider() {
return rider;
}
public void setRider(User rider) {
this.rider = rider;
}
public Double getLatitude() {
return latitude;
}
public void setLatitude(Double latitude) {
this.latitude = latitude;
}
public Double getLongitude() {
return longitude;
}
public void setLongitude(Double longitude) {
this.longitude = longitude;
}
}
RiderLocationRepository RiderLocationRepository
public interface RiderLocationRepository extends JpaRepository<RiderLocation, Long>{
@Query("select r.latitude,r.longitude from RiderLocation r ")
ArrayList<Object[]> findAllRidersLocation();
RiderLocation findByRider(@Param("rider_id") Long rider);
}
The problem is solved now the only mistake is I wrote 现在问题解决了,唯一的错误是我写的
findByRider(@Param("rider_id") Long rider);
instead of : 代替 :
findByRiderId(@Param("rider_id") Long rider);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.