结果集的排序分为以sql排序还有就是需要使用集合Collections方法进行排序
一、sql排序
sql排序分为升序和降序,默认使用的是升序asc,一般在开发中使用降序
order by column_name desc(上大下小)
二、使用集合的方法排序
Collections.sort(Collection)
一般需要重写对象的排序方法
@Table(name = "t_user_score1")
public class TUserScore1 implements Comparable<TUserScore1> {
@Id
@NotBlank
@Size(min = 6, max = 32)
@Column(name = "SCOREID")
private String scoreid;
@NotBlank
@Size(min = 6, max = 32)
@Column(name = "USERID")
private String userid;
@NotBlank
@Size(min = 6, max = 64)
@Column(name = "USERNAME")
private String username;
@DecimalMax("100")
@DecimalMin("0")
@Column(name = "SCORE")
private Double score;
/**
* @return SCOREID
*/
public String getScoreid() {
return scoreid;
}
/**
* @param scoreid
*/
public void setScoreid(String scoreid) {
this.scoreid = scoreid == null ? null : scoreid.trim();
}
/**
* @return USERID
*/
public String getUserid() {
return userid;
}
/**
* @param userid
*/
public void setUserid(String userid) {
this.userid = userid == null ? null : userid.trim();
}
/**
* @return USERNAME
*/
public String getUsername() {
return username;
}
/**
* @param username
*/
public void setUsername(String username) {
this.username = username == null ? null : username.trim();
}
/**
* @return SCORE
*/
public Double getScore() {
return score;
}
/**
* @param score
*/
public void setScore(Double score) {
this.score = score;
}
/**
* 降序 排列
*/
@Override
public int compareTo(TUserScore1 o) {
if (this.score - o.score > 0) {
return -1;
} else {
return 1;
}
}
}
网友评论