Spring #8
12397 ワード
ApiMessage
ApiMessage.java@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class ApiMessage<T>{
private int code;
private String message;
private T data;
public ApiMessage(Status status) {
this.code = status.getCode();
this.message = status.getMessage();
}
public static <T> ApiMessage<T> putDataInMessage(ApiMessage apiMessage,T data){
return (ApiMessage<T>) ApiMessage.builder()
.message(apiMessage.message)
.code(apiMessage.code)
.data(data)
.build();
}
public static ApiMessage getSuccessMessage(){
return new ApiMessage(Status.SUCCESS);
}
public static ApiMessage getFailMessage(){
return new ApiMessage(Status.FAIL);
}
public static ApiMessage getUnAuthorizationMessage(){
return new ApiMessage(Status.UN_AUTHORIZATION);
}
public static ApiMessage getArtistDoesNotExistError(){
return new ApiMessage(Status.ARTIST_DOES_NOT_EXIST);
}
@Getter
public enum Status{
SUCCESS(200, "Success"),
UN_AUTHORIZATION(403, "UnAuthorization")
, FAIL(403, "Fail")
, ARTIST_DOES_NOT_EXIST(403,"Artist is not exist");
private int code;
private String message;
Status(int code, String message){
this.code = code;
this.message = message;
}
}
}
Key,Value値を返す方法->Mapでよい.
Collections.sort
Collections.sort(list, (o1, o2) -> {
if(o1.getViewCount()<o2.getViewCount()){
return 1;
}else if(o1.getViewCount()>o2.getViewCount()){
return -1;
}
return 0;
});
後の大きな値に基づいて1->DESCを返します.
前の値より大きい場合は1->ASCを返します.
Reference
この問題について(Spring #8), 我々は、より多くの情報をここで見つけました
https://velog.io/@camel-man-ims/Spring-8
テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class ApiMessage<T>{
private int code;
private String message;
private T data;
public ApiMessage(Status status) {
this.code = status.getCode();
this.message = status.getMessage();
}
public static <T> ApiMessage<T> putDataInMessage(ApiMessage apiMessage,T data){
return (ApiMessage<T>) ApiMessage.builder()
.message(apiMessage.message)
.code(apiMessage.code)
.data(data)
.build();
}
public static ApiMessage getSuccessMessage(){
return new ApiMessage(Status.SUCCESS);
}
public static ApiMessage getFailMessage(){
return new ApiMessage(Status.FAIL);
}
public static ApiMessage getUnAuthorizationMessage(){
return new ApiMessage(Status.UN_AUTHORIZATION);
}
public static ApiMessage getArtistDoesNotExistError(){
return new ApiMessage(Status.ARTIST_DOES_NOT_EXIST);
}
@Getter
public enum Status{
SUCCESS(200, "Success"),
UN_AUTHORIZATION(403, "UnAuthorization")
, FAIL(403, "Fail")
, ARTIST_DOES_NOT_EXIST(403,"Artist is not exist");
private int code;
private String message;
Status(int code, String message){
this.code = code;
this.message = message;
}
}
}
Collections.sort(list, (o1, o2) -> {
if(o1.getViewCount()<o2.getViewCount()){
return 1;
}else if(o1.getViewCount()>o2.getViewCount()){
return -1;
}
return 0;
});
Reference
この問題について(Spring #8), 我々は、より多くの情報をここで見つけました https://velog.io/@camel-man-ims/Spring-8テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol