我有一个对象:
public class ListAnnotationsOrigin implements Serializable {
/**
*
*/
private static final long serialVersionUID = 8443084209405942551L;
@JsonProperty("opcombo")
private List<opcombo> listComboOp;
@JsonProperty("vicombo")
private List<vicombo> listComboVi;
@JsonProperty("vicombo")
private String vicombo;
@JsonProperty("viversion")
private String idVersionVi;
@JsonProperty("closed")
private String closed;
@JsonProperty("params")
private List<SegmentOrigin> listSegmentOrigin; // <-- here
// getters,setters etc.
我想要排序列表
@Entity
@Table(name = "SegmentOrigin")
public class SegmentOrigin implements Comparable<T>{ // <-- ERROR
....
@JsonProperty("idSegment")
private String idSegment;
public int compareTo(SegmentOrigin arg0) {
if (this.getIdSegment().compareTo(arg0.getIdSegment())) { // <<--ERROR type mismatch: cannot convert from int to boolean
return 1;
} else {
return 0;
}
}
}
在我的控制器中->
ListAnnotationsOrigin list = this.getListAnnotationsOrigin ();
return Collections.sort((List<SegmentOrigin>) list.getListSegmentOrigin());
我以有序的方式从ListAnnotationsOrigin发送列表,然后当我实现Comparable {时,出现红线“实现方法统一”
我导入->
public int compareTo(SegmentOrigin arg0) { ...
并收到其他错误,谢谢。 最佳答案
您的实体应如下所示:
@Entity
@Table(name = "SegmentOrigin")
public class SegmentOrigin implements Comparable<SegmentOrigin>{
@JsonProperty("idSegment")
private String idSegment;
public int compareTo(SegmentOrigin arg0) {
return this.getIdSegment().compareTo(arg0.getIdSegment()); // Check nullity if needed
}
}
implements Comparable<SegmentOrigin>
表示可以将您的对象与另一个SegmentOrigin对象进行比较。