精简util模块,ReturenResponse重构
This commit is contained in:
@ -50,9 +50,25 @@ public enum FileType {
|
||||
FILE_TYPE_MAPPER.put("dwg", FileType.cad);
|
||||
}
|
||||
|
||||
public static FileType to(String fileType){
|
||||
private static FileType to(String fileType){
|
||||
return FILE_TYPE_MAPPER.getOrDefault(fileType,other);
|
||||
}
|
||||
/**
|
||||
* 查看文件类型(防止参数中存在.点号或者其他特殊字符,所以先抽取文件名,然后再获取文件类型)
|
||||
*
|
||||
* @param url url
|
||||
* @return 文件类型
|
||||
*/
|
||||
public static FileType typeFromUrl(String url) {
|
||||
String nonPramStr = url.substring(0, url.contains("?") ? url.indexOf("?") : url.length());
|
||||
String fileName = nonPramStr.substring(nonPramStr.lastIndexOf("/") + 1);
|
||||
return typeFromFileName(fileName);
|
||||
}
|
||||
|
||||
public static FileType typeFromFileName(String fileName) {
|
||||
String fileType = fileName.substring(fileName.lastIndexOf(".") + 1);
|
||||
return FileType.to(fileType);
|
||||
}
|
||||
|
||||
private final String instanceName;
|
||||
|
||||
|
||||
@ -4,11 +4,18 @@ import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 接口返回值结构
|
||||
*
|
||||
* @author yudian-it
|
||||
* @date 2017/11/17
|
||||
*/
|
||||
public class ReturnResponse<T> implements Serializable{
|
||||
public class ReturnResponse<T> implements Serializable {
|
||||
private static final long serialVersionUID = 313975329998789878L;
|
||||
|
||||
public static final int SUCCESS_CODE = 0;
|
||||
public static final int FAILURE_CODE = 1;
|
||||
public static final String SUCCESS_MSG = "SUCCESS";
|
||||
public static final String FAILURE_MSG = "FAILURE";
|
||||
|
||||
/**
|
||||
* 返回状态
|
||||
* 0. 成功
|
||||
@ -31,6 +38,30 @@ public class ReturnResponse<T> implements Serializable{
|
||||
this.content = content;
|
||||
}
|
||||
|
||||
public static ReturnResponse<Object> failure(String errMsg) {
|
||||
return new ReturnResponse<>(FAILURE_CODE, errMsg, null);
|
||||
}
|
||||
|
||||
public static ReturnResponse<Object> failure() {
|
||||
return failure(FAILURE_MSG);
|
||||
}
|
||||
|
||||
public static ReturnResponse<Object> success(){
|
||||
return success(null);
|
||||
}
|
||||
|
||||
public static ReturnResponse<Object> success(Object content) {
|
||||
return new ReturnResponse<>(SUCCESS_CODE, SUCCESS_MSG, content);
|
||||
}
|
||||
|
||||
public boolean isSuccess(){
|
||||
return SUCCESS_CODE == code;
|
||||
}
|
||||
|
||||
public boolean isFailure(){
|
||||
return !isSuccess();
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user