0
我爲後端API使用Play2.0框架。所以我想從數據庫的遊樂設施列表,我想排除具有重複「地點」名稱的乘坐。排除PagedList中的重複數據
我正在使用此代碼,但這給了我存儲在數據庫中的所有遊樂設施記錄。如何排除細膩的條目?
這裏是Java代碼
public List<RideDTO> recent(long userId, int cursor, int count) {
PagedList<RideDTO> pagedList = RideDTO.find
.where()
.eq("user_id", userId)
.orderBy("created_on desc")
.findPagedList(cursor, count);
if (pagedList == null)
return null;
else
return pagedList.getList();
}
這裏是RideDTO模型類。我不想在數據庫中保持獨一無二的地位。
@Entity
@Table(name = "m_ride")
//@UniqueConstraint(columnNames = {"place"})
public class RideDTO extends Model {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@NotNull
@Constraints.Required
private long id;
@ManyToOne
@NotNull
@Constraints.Required
private UserDTO user;
@NotNull
@Constraints.Required
private String place;
@NotNull
@Constraints.Required
private double startLat;
@NotNull
@Constraints.Required
private double startLng;
@NotNull
@Constraints.Required
private double destLat;
@NotNull
@Constraints.Required
private double destLng;
private double currLat;
private double currLng;
@NotNull
@Constraints.Required
private short isFav;
private String image;
@NotNull
@CreatedTimestamp
@Constraints.Required
private Date createdOn;
@Transient
private double distance;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public UserDTO getUser() {
return user;
}
public void setUser(UserDTO user) {
this.user = user;
}
public String getPlace() {
return place;
}
public void setPlace(String place) {
this.place = place;
}
public double getStartLat() {
return startLat;
}
public void setStartLat(double startLat) {
this.startLat = startLat;
}
public double getStartLng() {
return startLng;
}
public void setStartLng(double startLng) {
this.startLng = startLng;
}
public double getDestLat() {
return destLat;
}
public void setDestLat(double destLat) {
this.destLat = destLat;
}
public double getDestLng() {
return destLng;
}
public void setDestLng(double destLng) {
this.destLng = destLng;
}
public double getCurrLat() {
return currLat;
}
public void setCurrLat(double currLat) {
this.currLat = currLat;
}
public double getCurrLng() {
return currLng;
}
public void setCurrLng(double currLng) {
this.currLng = currLng;
}
public short getIsFav() {
return isFav;
}
public void setIsFav(short isFav) {
this.isFav = isFav;
}
public String getImage() {
return image;
}
public void setImage(String image) {
this.image = image;
}
public Date getCreatedOn() {
return createdOn;
}
public void setCreatedOn(Date createdOn) {
this.createdOn = createdOn;
}
public double getDistance() {
return distance;
}
public void setDistance(double distance) {
this.distance = distance;
}
@Override
public String toString() {
return "RideDTO{" +
"id=" + id +
", user=" + user +
", place='" + place + '\'' +
", startLat=" + startLat +
", startLng=" + startLng +
", destLat=" + destLat +
", destLng=" + destLng +
", currLat=" + currLat +
", currLng=" + currLng +
", isFav=" + isFav +
", image='" + image + '\'' +
", createdOn=" + createdOn +
", distance=" + distance +
'}';
}
public static final Finder<Long, RideDTO> find = new Finder<Long, RideDTO>(Long.class, RideDTO.class);
}
你錯過了重要的部分,你爲哪一列申請'DISTINCT'。這裏的專欄是'place' – Sivakumar
@Sivakumar,謝謝。 –
謝謝配偶。我會檢查按照這個按照下面的答案,然後會回來給你們 –