我有以下代码,其中我想获得骑手的id,但我不知道如何做到这一点,实际上rider是链接到RiderLocation
表的用户类型,当我改变时用户的骑手类型然后我不能像这样
http://localhost:3000/api/riderLocations/search/findByRider?rider_id=3
代码低于
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
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);
}
答案 0 :(得分:0)
问题现在解决了 唯一的错误是我写的
findByRider(@Param("rider_id") Long rider);
而不是:
findByRiderId(@Param("rider_id") Long rider);