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
http://localhost:3000/api/riderLocations/search/findByRider?rider_id=3
Code is below
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);
}
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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.