增加RestResult功能
This commit is contained in:
@@ -508,6 +508,9 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
||||
} else {
|
||||
finish(convert, result.getResult());
|
||||
}
|
||||
} else if (obj instanceof RestResult) {
|
||||
RestResult result = (RestResult) obj;
|
||||
finish(result.getConvert() == null ? request.getJsonConvert() : result.getConvert(), type, result.getResult());
|
||||
} else {
|
||||
if (hasRender) {
|
||||
if (onlyoneHttpRender != null) {
|
||||
|
||||
@@ -22,17 +22,17 @@ public class HttpResult<T> {
|
||||
|
||||
public static final String SESSIONID_COOKIENAME = HttpRequest.SESSIONID_NAME;
|
||||
|
||||
private Map<String, String> headers;
|
||||
protected Map<String, String> headers;
|
||||
|
||||
private List<HttpCookie> cookies;
|
||||
protected List<HttpCookie> cookies;
|
||||
|
||||
private String contentType;
|
||||
protected String contentType;
|
||||
|
||||
private T result;
|
||||
protected T result;
|
||||
|
||||
private int status = 0; //不设置则为 200
|
||||
protected int status = 0; //不设置则为 200
|
||||
|
||||
private String message;
|
||||
protected String message;
|
||||
|
||||
public HttpResult() {
|
||||
}
|
||||
|
||||
49
src/org/redkale/net/http/RestResult.java
Normal file
49
src/org/redkale/net/http/RestResult.java
Normal file
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.redkale.net.http;
|
||||
|
||||
import org.redkale.convert.Convert;
|
||||
|
||||
/**
|
||||
* 当RestMapping方法需要指定Convert进行序列化时将结果和Convert对象绑定输出
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
* @param <T> 结果对象的类型
|
||||
*/
|
||||
public class RestResult<T> {
|
||||
|
||||
protected Convert convert;
|
||||
|
||||
protected T result;
|
||||
|
||||
public RestResult() {
|
||||
}
|
||||
|
||||
public RestResult(Convert convert, T result) {
|
||||
this.convert = convert;
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
public Convert getConvert() {
|
||||
return convert;
|
||||
}
|
||||
|
||||
public void setConvert(Convert convert) {
|
||||
this.convert = convert;
|
||||
}
|
||||
|
||||
public T getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(T result) {
|
||||
this.result = result;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user