This commit is contained in:
@@ -907,4 +907,73 @@ public class HttpRequest extends Request<HttpContext> {
|
||||
return params.getDoubleValue(name, defaultValue);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取翻页对象 同 findFlipper("flipper", false, 0);
|
||||
*
|
||||
* @return Flipper翻页对象
|
||||
*/
|
||||
public org.redkale.source.Flipper findFlipper() {
|
||||
return findFlipper(false, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取翻页对象 同 findFlipper("flipper", needcreate, 0);
|
||||
*
|
||||
* @param needcreate 无参数时是否创建新Flipper对象
|
||||
*
|
||||
* @return Flipper翻页对象
|
||||
*/
|
||||
public org.redkale.source.Flipper findFlipper(boolean needcreate) {
|
||||
return findFlipper(needcreate, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取翻页对象 同 findFlipper("flipper", false, maxLimit);
|
||||
*
|
||||
* @param maxLimit 最大行数, 小于1则值为Flipper.DEFAULT_LIMIT
|
||||
*
|
||||
* @return Flipper翻页对象
|
||||
*/
|
||||
public org.redkale.source.Flipper findFlipper(int maxLimit) {
|
||||
return findFlipper(false, maxLimit);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取翻页对象 同 findFlipper("flipper", needcreate, maxLimit)
|
||||
*
|
||||
* @param needcreate 无参数时是否创建新Flipper对象
|
||||
* @param maxLimit 最大行数, 小于1则值为Flipper.DEFAULT_LIMIT
|
||||
*
|
||||
* @return Flipper翻页对象
|
||||
*/
|
||||
public org.redkale.source.Flipper findFlipper(boolean needcreate, int maxLimit) {
|
||||
return findFlipper("flipper", needcreate, maxLimit);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取翻页对象 http://redkale.org/pipes/records/list/offset:0/limit:20/sort:createtime%20ASC <br>
|
||||
* http://redkale.org/pipes/records/list?flipper={'offset':0,'limit':20, 'sort':'createtime ASC'} <br>
|
||||
* 以上两种接口都可以获取到翻页对象
|
||||
*
|
||||
*
|
||||
* @param name Flipper对象的参数名,默认为 "flipper"
|
||||
* @param needcreate 无参数时是否创建新Flipper对象
|
||||
* @param maxLimit 最大行数, 小于1则值为Flipper.DEFAULT_LIMIT
|
||||
*
|
||||
* @return Flipper翻页对象
|
||||
*/
|
||||
public org.redkale.source.Flipper findFlipper(String name, boolean needcreate, int maxLimit) {
|
||||
if (maxLimit < 1) maxLimit = org.redkale.source.Flipper.DEFAULT_LIMIT;
|
||||
org.redkale.source.Flipper flipper = getJsonParameter(org.redkale.source.Flipper.class, name);
|
||||
if (flipper == null) {
|
||||
int limit = getRequstURIPath("limit:", maxLimit);
|
||||
int offset = getRequstURIPath("offset:", 0);
|
||||
String sort = getRequstURIPath("sort:", "");
|
||||
if (limit > 0) flipper = new org.redkale.source.Flipper(limit, offset, sort);
|
||||
} else if (flipper.getLimit() < 1 || flipper.getLimit() > maxLimit) {
|
||||
flipper.setLimit(maxLimit);
|
||||
}
|
||||
if (flipper != null || !needcreate) return flipper;
|
||||
return new org.redkale.source.Flipper(maxLimit);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,6 +160,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
||||
* 获取状态码对应的状态描述
|
||||
*
|
||||
* @param status 状态码
|
||||
*
|
||||
* @return 状态描述
|
||||
*/
|
||||
protected String getHttpCode(int status) {
|
||||
@@ -179,6 +180,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
||||
* 增加Cookie值
|
||||
*
|
||||
* @param cookies cookie
|
||||
*
|
||||
* @return HttpResponse
|
||||
*/
|
||||
public HttpResponse addCookie(HttpCookie... cookies) {
|
||||
@@ -247,6 +249,35 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
||||
finish(request.getJsonConvert().convertTo(context.getBufferSupplier(), objs));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将RetResult对象以JSON格式输出
|
||||
*
|
||||
* @param ret RetResult输出对象
|
||||
*/
|
||||
public void finishJson(final org.redkale.service.RetResult ret) {
|
||||
this.contentType = "text/plain; charset=utf-8";
|
||||
if (ret != null && !ret.isSuccess()) {
|
||||
addHeader("retcode", ret.getRetcode());
|
||||
addHeader("retinfo", ret.getRetinfo());
|
||||
}
|
||||
finish(request.getJsonConvert().convertTo(context.getBufferSupplier(), ret));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将RetResult对象以JSON格式输出
|
||||
*
|
||||
* @param convert 指定的JsonConvert
|
||||
* @param ret RetResult输出对象
|
||||
*/
|
||||
public void finishJson(final JsonConvert convert, final org.redkale.service.RetResult ret) {
|
||||
this.contentType = "text/plain; charset=utf-8";
|
||||
if (ret != null && !ret.isSuccess()) {
|
||||
addHeader("retcode", ret.getRetcode());
|
||||
addHeader("retinfo", ret.getRetinfo());
|
||||
}
|
||||
finish(convert.convertTo(context.getBufferSupplier(), ret));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将指定字符串以响应结果输出
|
||||
*
|
||||
@@ -415,6 +446,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
||||
* 将指定文件按响应结果输出
|
||||
*
|
||||
* @param file 输出文件
|
||||
*
|
||||
* @throws IOException IO异常
|
||||
*/
|
||||
public void finish(File file) throws IOException {
|
||||
@@ -426,6 +458,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
||||
*
|
||||
* @param filename 输出文件名
|
||||
* @param file 输出文件
|
||||
*
|
||||
* @throws IOException IO异常
|
||||
*/
|
||||
public void finish(final String filename, File file) throws IOException {
|
||||
@@ -437,6 +470,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
||||
*
|
||||
* @param file 输出文件
|
||||
* @param fileBody 文件内容, 没有则输出file
|
||||
*
|
||||
* @throws IOException IO异常
|
||||
*/
|
||||
protected void finishFile(final File file, ByteBuffer fileBody) throws IOException {
|
||||
@@ -449,6 +483,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
||||
* @param filename 输出文件名
|
||||
* @param file 输出文件
|
||||
* @param fileBody 文件内容, 没有则输出file
|
||||
*
|
||||
* @throws IOException IO异常
|
||||
*/
|
||||
protected void finishFile(final String filename, final File file, ByteBuffer fileBody) throws IOException {
|
||||
@@ -611,6 +646,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
||||
*
|
||||
* @param name header名
|
||||
* @param value header值
|
||||
*
|
||||
* @return HttpResponse
|
||||
*/
|
||||
public HttpResponse setHeader(String name, Object value) {
|
||||
@@ -623,6 +659,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
||||
*
|
||||
* @param name header名
|
||||
* @param value header值
|
||||
*
|
||||
* @return HttpResponse
|
||||
*/
|
||||
public HttpResponse addHeader(String name, Object value) {
|
||||
@@ -634,6 +671,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
||||
* 设置状态码
|
||||
*
|
||||
* @param status 状态码
|
||||
*
|
||||
* @return HttpResponse
|
||||
*/
|
||||
public HttpResponse setStatus(int status) {
|
||||
@@ -663,6 +701,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
||||
* 设置 ContentType
|
||||
*
|
||||
* @param contentType ContentType
|
||||
*
|
||||
* @return HttpResponse
|
||||
*/
|
||||
public HttpResponse setContentType(String contentType) {
|
||||
@@ -683,6 +722,7 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
||||
* 设置内容长度
|
||||
*
|
||||
* @param contentLength 内容长度
|
||||
*
|
||||
* @return HttpResponse
|
||||
*/
|
||||
public HttpResponse setContentLength(long contentLength) {
|
||||
|
||||
Reference in New Issue
Block a user