删掉HttpResponse.finishJsResult方法
This commit is contained in:
@@ -290,31 +290,6 @@ public class HttpResponse extends Response<HttpContext, HttpRequest> {
|
||||
finish(convert.convertTo(context.getBufferSupplier(), ret));
|
||||
}
|
||||
|
||||
/**
|
||||
* 将对象以JavaScript格式输出
|
||||
*
|
||||
* @param var js变量名
|
||||
* @param result 输出对象
|
||||
*/
|
||||
public void finishJsResult(String var, Object result) {
|
||||
this.contentType = "application/javascript; charset=utf-8";
|
||||
if (this.recycleListener != null) this.output = result;
|
||||
finish("var " + var + " = " + request.getJsonConvert().convertTo(result) + ";");
|
||||
}
|
||||
|
||||
/**
|
||||
* 将对象以JavaScript格式输出
|
||||
*
|
||||
* @param jsonConvert 指定的JsonConvert
|
||||
* @param var js变量名
|
||||
* @param result 输出对象
|
||||
*/
|
||||
public void finishJsResult(JsonConvert jsonConvert, String var, Object result) {
|
||||
this.contentType = "application/javascript; charset=utf-8";
|
||||
if (this.recycleListener != null) this.output = result;
|
||||
finish("var " + var + " = " + jsonConvert.convertTo(result) + ";");
|
||||
}
|
||||
|
||||
/**
|
||||
* 将指定字符串以响应结果输出
|
||||
*
|
||||
|
||||
@@ -254,7 +254,6 @@ public final class Rest {
|
||||
final int maxStack = 3 + params.length;
|
||||
List<int[]> varInsns = new ArrayList<>();
|
||||
int maxLocals = 4;
|
||||
final String jsvar = entry.jsvar.isEmpty() ? null : entry.jsvar;
|
||||
int argIndex = 0;
|
||||
|
||||
List<Object[]> paramlist = new ArrayList<>();
|
||||
@@ -731,214 +730,110 @@ public final class Rest {
|
||||
mv.visitInsn(RETURN);
|
||||
} else if (returnType == boolean.class) {
|
||||
mv.visitVarInsn(ISTORE, maxLocals);
|
||||
if (jsvar == null) {
|
||||
mv.visitVarInsn(ALOAD, 2); //response
|
||||
mv.visitVarInsn(ILOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "valueOf", "(Z)Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finish", "(Ljava/lang/String;)V", false);
|
||||
} else {
|
||||
mv.visitVarInsn(ALOAD, 2);
|
||||
mv.visitLdcInsn(jsvar);
|
||||
mv.visitVarInsn(ILOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Boolean", "valueOf", "(Z)Ljava/lang/Boolean;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finishJsResult", "(Ljava/lang/String;Ljava/lang/Object;)V", false);
|
||||
}
|
||||
mv.visitVarInsn(ALOAD, 2); //response
|
||||
mv.visitVarInsn(ILOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "valueOf", "(Z)Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finish", "(Ljava/lang/String;)V", false);
|
||||
mv.visitInsn(RETURN);
|
||||
maxLocals++;
|
||||
} else if (returnType == byte.class) {
|
||||
mv.visitVarInsn(ISTORE, maxLocals);
|
||||
if (jsvar == null) {
|
||||
mv.visitVarInsn(ALOAD, 2); //response
|
||||
mv.visitVarInsn(ILOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "valueOf", "(I)Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finish", "(Ljava/lang/String;)V", false);
|
||||
} else {
|
||||
mv.visitVarInsn(ALOAD, 2);
|
||||
mv.visitLdcInsn(jsvar);
|
||||
mv.visitVarInsn(ILOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Byte", "valueOf", "(B)Ljava/lang/Byte;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finishJsResult", "(Ljava/lang/String;Ljava/lang/Object;)V", false);
|
||||
}
|
||||
mv.visitVarInsn(ALOAD, 2); //response
|
||||
mv.visitVarInsn(ILOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "valueOf", "(I)Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finish", "(Ljava/lang/String;)V", false);
|
||||
mv.visitInsn(RETURN);
|
||||
maxLocals++;
|
||||
} else if (returnType == short.class) {
|
||||
mv.visitVarInsn(ISTORE, maxLocals);
|
||||
if (jsvar == null) {
|
||||
mv.visitVarInsn(ALOAD, 2); //response
|
||||
mv.visitVarInsn(ILOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "valueOf", "(I)Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finish", "(Ljava/lang/String;)V", false);
|
||||
} else {
|
||||
mv.visitVarInsn(ALOAD, 2);
|
||||
mv.visitLdcInsn(jsvar);
|
||||
mv.visitVarInsn(ILOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Short", "valueOf", "(S)Ljava/lang/Short;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finishJsResult", "(Ljava/lang/String;Ljava/lang/Object;)V", false);
|
||||
}
|
||||
mv.visitVarInsn(ALOAD, 2); //response
|
||||
mv.visitVarInsn(ILOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "valueOf", "(I)Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finish", "(Ljava/lang/String;)V", false);
|
||||
mv.visitInsn(RETURN);
|
||||
maxLocals++;
|
||||
} else if (returnType == char.class) {
|
||||
mv.visitVarInsn(ISTORE, maxLocals);
|
||||
if (jsvar == null) {
|
||||
mv.visitVarInsn(ALOAD, 2); //response
|
||||
mv.visitVarInsn(ILOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "valueOf", "(C)Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finish", "(Ljava/lang/String;)V", false);
|
||||
} else {
|
||||
mv.visitVarInsn(ALOAD, 2);
|
||||
mv.visitLdcInsn(jsvar);
|
||||
mv.visitVarInsn(ILOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Character", "valueOf", "(C)Ljava/lang/Character;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finishJsResult", "(Ljava/lang/String;Ljava/lang/Object;)V", false);
|
||||
}
|
||||
mv.visitVarInsn(ALOAD, 2); //response
|
||||
mv.visitVarInsn(ILOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "valueOf", "(C)Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finish", "(Ljava/lang/String;)V", false);
|
||||
mv.visitInsn(RETURN);
|
||||
maxLocals++;
|
||||
} else if (returnType == int.class) {
|
||||
mv.visitVarInsn(ISTORE, maxLocals);
|
||||
if (jsvar == null) {
|
||||
mv.visitVarInsn(ALOAD, 2); //response
|
||||
mv.visitVarInsn(ILOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "valueOf", "(I)Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finish", "(Ljava/lang/String;)V", false);
|
||||
} else {
|
||||
mv.visitVarInsn(ALOAD, 2);
|
||||
mv.visitLdcInsn(jsvar);
|
||||
mv.visitVarInsn(ILOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finishJsResult", "(Ljava/lang/String;Ljava/lang/Object;)V", false);
|
||||
}
|
||||
mv.visitVarInsn(ALOAD, 2); //response
|
||||
mv.visitVarInsn(ILOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "valueOf", "(I)Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finish", "(Ljava/lang/String;)V", false);
|
||||
mv.visitInsn(RETURN);
|
||||
maxLocals++;
|
||||
} else if (returnType == float.class) {
|
||||
mv.visitVarInsn(FSTORE, maxLocals);
|
||||
if (jsvar == null) {
|
||||
mv.visitVarInsn(ALOAD, 2); //response
|
||||
mv.visitVarInsn(FLOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "valueOf", "(F)Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finish", "(Ljava/lang/String;)V", false);
|
||||
} else {
|
||||
mv.visitVarInsn(ALOAD, 2);
|
||||
mv.visitLdcInsn(jsvar);
|
||||
mv.visitVarInsn(FLOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Float", "valueOf", "(F)Ljava/lang/Float;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finishJsResult", "(Ljava/lang/String;Ljava/lang/Object;)V", false);
|
||||
}
|
||||
mv.visitVarInsn(ALOAD, 2); //response
|
||||
mv.visitVarInsn(FLOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "valueOf", "(F)Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finish", "(Ljava/lang/String;)V", false);
|
||||
mv.visitInsn(RETURN);
|
||||
maxLocals++;
|
||||
} else if (returnType == long.class) {
|
||||
mv.visitVarInsn(LSTORE, maxLocals);
|
||||
if (jsvar == null) {
|
||||
mv.visitVarInsn(ALOAD, 2); //response
|
||||
mv.visitVarInsn(LLOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "valueOf", "(J)Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finish", "(Ljava/lang/String;)V", false);
|
||||
} else {
|
||||
mv.visitVarInsn(ALOAD, 2);
|
||||
mv.visitLdcInsn(jsvar);
|
||||
mv.visitVarInsn(LLOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Long", "valueOf", "(J)Ljava/lang/Long;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finishJsResult", "(Ljava/lang/String;Ljava/lang/Object;)V", false);
|
||||
}
|
||||
mv.visitVarInsn(ALOAD, 2); //response
|
||||
mv.visitVarInsn(LLOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "valueOf", "(J)Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finish", "(Ljava/lang/String;)V", false);
|
||||
mv.visitInsn(RETURN);
|
||||
maxLocals += 2;
|
||||
} else if (returnType == double.class) {
|
||||
mv.visitVarInsn(DSTORE, maxLocals);
|
||||
if (jsvar == null) {
|
||||
mv.visitVarInsn(ALOAD, 2); //response
|
||||
mv.visitVarInsn(DLOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "valueOf", "(D)Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finish", "(Ljava/lang/String;)V", false);
|
||||
} else {
|
||||
mv.visitVarInsn(ALOAD, 2);
|
||||
mv.visitLdcInsn(jsvar);
|
||||
mv.visitVarInsn(DLOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Double", "valueOf", "(D)Ljava/lang/Double;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finishJsResult", "(Ljava/lang/String;Ljava/lang/Object;)V", false);
|
||||
}
|
||||
mv.visitVarInsn(ALOAD, 2); //response
|
||||
mv.visitVarInsn(DLOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "valueOf", "(D)Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finish", "(Ljava/lang/String;)V", false);
|
||||
mv.visitInsn(RETURN);
|
||||
maxLocals += 2;
|
||||
} else if (returnType == String.class) {
|
||||
mv.visitVarInsn(ASTORE, maxLocals);
|
||||
if (jsvar == null) {
|
||||
mv.visitVarInsn(ALOAD, 2); //response
|
||||
mv.visitVarInsn(ALOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finish", "(Ljava/lang/String;)V", false);
|
||||
} else {
|
||||
mv.visitVarInsn(ALOAD, 2);
|
||||
mv.visitLdcInsn(jsvar);
|
||||
mv.visitVarInsn(ALOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finishJsResult", "(Ljava/lang/String;Ljava/lang/Object;)V", false);
|
||||
}
|
||||
mv.visitVarInsn(ALOAD, 2); //response
|
||||
mv.visitVarInsn(ALOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finish", "(Ljava/lang/String;)V", false);
|
||||
mv.visitInsn(RETURN);
|
||||
maxLocals++;
|
||||
} else if (returnType == File.class) {
|
||||
mv.visitVarInsn(ASTORE, maxLocals);
|
||||
if (jsvar == null) {
|
||||
mv.visitVarInsn(ALOAD, 2); //response
|
||||
mv.visitVarInsn(ALOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finish", "(Ljava/io/File;)V", false);
|
||||
} else {
|
||||
throw new RuntimeException(method + " cannot set return Type (java.io.File) to jsvar");
|
||||
}
|
||||
mv.visitVarInsn(ALOAD, 2); //response
|
||||
mv.visitVarInsn(ALOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finish", "(Ljava/io/File;)V", false);
|
||||
mv.visitInsn(RETURN);
|
||||
maxLocals++;
|
||||
} else if (RetResult.class.isAssignableFrom(returnType)) {
|
||||
mv.visitVarInsn(ASTORE, maxLocals);
|
||||
if (jsvar == null) {
|
||||
mv.visitVarInsn(ALOAD, 2); //response
|
||||
mv.visitVarInsn(ALOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finishJson", "(" + retDesc + ")V", false);
|
||||
} else {
|
||||
mv.visitVarInsn(ALOAD, 2);
|
||||
mv.visitLdcInsn(jsvar);
|
||||
mv.visitVarInsn(ALOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finishJsResult", "(Ljava/lang/String;Ljava/lang/Object;)V", false);
|
||||
}
|
||||
mv.visitVarInsn(ALOAD, 2); //response
|
||||
mv.visitVarInsn(ALOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finishJson", "(" + retDesc + ")V", false);
|
||||
mv.visitInsn(RETURN);
|
||||
maxLocals++;
|
||||
} else if (RestOutput.class.isAssignableFrom(returnType)) {
|
||||
mv.visitVarInsn(ASTORE, maxLocals);
|
||||
if (jsvar == null) {
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitVarInsn(ALOAD, 2);
|
||||
mv.visitVarInsn(ALOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, newDynName, "finishJson", "(" + respDesc + restoutputDesc + ")V", false);
|
||||
} else {
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitVarInsn(ALOAD, 2);
|
||||
mv.visitLdcInsn(jsvar);
|
||||
mv.visitVarInsn(ALOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, newDynName, "finishJsResult", "(" + respDesc + "Ljava/lang/String;" + restoutputDesc + ")V", false);
|
||||
}
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitVarInsn(ALOAD, 2);
|
||||
mv.visitVarInsn(ALOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, newDynName, "finishJson", "(" + respDesc + restoutputDesc + ")V", false);
|
||||
mv.visitInsn(RETURN);
|
||||
maxLocals++;
|
||||
} else if (Number.class.isAssignableFrom(returnType) || CharSequence.class.isAssignableFrom(returnType)) { //returnType == String.class 必须放在前面
|
||||
mv.visitVarInsn(ASTORE, maxLocals);
|
||||
if (jsvar == null) {
|
||||
mv.visitVarInsn(ALOAD, 2); //response
|
||||
mv.visitVarInsn(ALOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "valueOf", "(Ljava/lang/Object;)Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finish", "(Ljava/lang/String;)V", false);
|
||||
} else {
|
||||
mv.visitVarInsn(ALOAD, 2);
|
||||
mv.visitLdcInsn(jsvar);
|
||||
mv.visitVarInsn(ALOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finishJsResult", "(Ljava/lang/String;Ljava/lang/Object;)V", false);
|
||||
}
|
||||
mv.visitVarInsn(ALOAD, 2); //response
|
||||
mv.visitVarInsn(ALOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKESTATIC, "java/lang/String", "valueOf", "(Ljava/lang/Object;)Ljava/lang/String;", false);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finish", "(Ljava/lang/String;)V", false);
|
||||
mv.visitInsn(RETURN);
|
||||
maxLocals++;
|
||||
} else {
|
||||
mv.visitVarInsn(ASTORE, maxLocals);
|
||||
if (jsvar == null) {
|
||||
mv.visitVarInsn(ALOAD, 2); //response
|
||||
mv.visitVarInsn(ALOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finishJson", "(Ljava/lang/Object;)V", false);
|
||||
} else {
|
||||
mv.visitVarInsn(ALOAD, 2);
|
||||
mv.visitLdcInsn(jsvar);
|
||||
mv.visitVarInsn(ALOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finishJsResult", "(Ljava/lang/String;Ljava/lang/Object;)V", false);
|
||||
}
|
||||
mv.visitVarInsn(ALOAD, 2); //response
|
||||
mv.visitVarInsn(ALOAD, maxLocals);
|
||||
mv.visitMethodInsn(INVOKEVIRTUAL, respInternalName, "finishJson", "(Ljava/lang/Object;)V", false);
|
||||
mv.visitInsn(RETURN);
|
||||
maxLocals++;
|
||||
}
|
||||
@@ -1020,7 +915,6 @@ public final class Rest {
|
||||
this.actionid = mapping.actionid();
|
||||
this.cacheseconds = mapping.cacheseconds();
|
||||
this.comment = mapping.comment();
|
||||
this.jsvar = mapping.jsvar();
|
||||
}
|
||||
|
||||
public final Method mappingMethod;
|
||||
@@ -1039,8 +933,6 @@ public final class Rest {
|
||||
|
||||
public final int cacheseconds;
|
||||
|
||||
public final String jsvar;
|
||||
|
||||
@RestMapping()
|
||||
void mapping() { //用于获取Mapping 默认值
|
||||
}
|
||||
|
||||
@@ -23,22 +23,17 @@ public abstract class RestHttpServlet<T> extends HttpBaseServlet {
|
||||
response.finishJson(output);
|
||||
return;
|
||||
}
|
||||
if (output.getContentType() != null) response.setContentType(output.getContentType());
|
||||
response.addHeader(output.getHeaders());
|
||||
response.addCookie(output.getCookies());
|
||||
|
||||
if (output.getResult() instanceof File) {
|
||||
response.finish((File) output.getResult());
|
||||
} else if (output.getResult() instanceof String) {
|
||||
response.finish((String) output.getResult());
|
||||
} else {
|
||||
response.finishJson(output.getResult());
|
||||
}
|
||||
}
|
||||
|
||||
protected void finishJsResult(final HttpResponse response, final String var, RestOutput output) throws IOException {
|
||||
if (output != null) {
|
||||
response.addHeader(output.getHeaders());
|
||||
response.addCookie(output.getCookies());
|
||||
}
|
||||
response.finishJsResult(var, output == null ? null : output.getResult());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -74,10 +74,4 @@ public @interface RestMapping {
|
||||
*/
|
||||
String[] methods() default {};
|
||||
|
||||
/**
|
||||
* 以application/javascript输出对象是指明js的对象名,该值存在时则忽略contentType()的值
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
String jsvar() default "";
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ public class RestOutput<T> {
|
||||
|
||||
private List<HttpCookie> cookies;
|
||||
|
||||
private String contentType;
|
||||
|
||||
private T result;
|
||||
|
||||
public RestOutput() {
|
||||
@@ -58,6 +60,14 @@ public class RestOutput<T> {
|
||||
this.cookies = cookies;
|
||||
}
|
||||
|
||||
public String getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
public void setContentType(String contentType) {
|
||||
this.contentType = contentType;
|
||||
}
|
||||
|
||||
public T getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -72,7 +72,6 @@ public class HelloService implements Service {
|
||||
|
||||
//查询单个
|
||||
@RestMapping(name = "find")
|
||||
@RestMapping(name = "jsfind", jsvar = "varhello")
|
||||
public HelloEntity findHello(@RestParam(name = "#") int id) { //通过 /pipes/hello/find/1234、/pipes/hello/jsfind/1234 查询对象
|
||||
return source.find(HelloEntity.class, id);
|
||||
}
|
||||
|
||||
@@ -46,8 +46,8 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
public void create(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
||||
HelloEntity bean = req.getJsonParameter(HelloEntity.class, "bean");
|
||||
bean.setClientaddr(req.getRemoteAddr());
|
||||
bean.setResname(req.getHeader("hello-res"));
|
||||
bean.setClientaddr(req.getRemoteAddr());
|
||||
bean.setResname(req.getHeader("hello-res"));
|
||||
UserInfo user = currentUser(req);
|
||||
RetResult<HelloEntity> result = service.createHello(user, bean);
|
||||
resp.finishJson(result);
|
||||
@@ -68,8 +68,8 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
HelloService service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
||||
String clientaddr = req.getRemoteAddr();
|
||||
HelloEntity bean = req.getJsonParameter(HelloEntity.class, "bean");
|
||||
bean.setClientaddr(req.getRemoteAddr());
|
||||
bean.setResname(req.getHeader("hello-res"));
|
||||
bean.setClientaddr(req.getRemoteAddr());
|
||||
bean.setResname(req.getHeader("hello-res"));
|
||||
service.updateHello(clientaddr, bean);
|
||||
resp.finishJson(RetResult.success());
|
||||
}
|
||||
@@ -79,8 +79,8 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
public void partupdate(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
||||
HelloEntity bean = req.getJsonParameter(HelloEntity.class, "bean");
|
||||
bean.setClientaddr(req.getRemoteAddr());
|
||||
bean.setResname(req.getHeader("hello-res"));
|
||||
bean.setClientaddr(req.getRemoteAddr());
|
||||
bean.setResname(req.getHeader("hello-res"));
|
||||
String[] cols = req.getJsonParameter(String[].class, "cols");
|
||||
service.updateHello(bean, cols);
|
||||
resp.finishJson(RetResult.success());
|
||||
@@ -91,10 +91,10 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
public void query(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
||||
HelloBean bean = req.getJsonParameter(HelloBean.class, "bean");
|
||||
bean.setClientaddr(req.getRemoteAddr());
|
||||
bean.setUseragent(req.getHeader("User-Agent"));
|
||||
bean.setRescookie(req.getCookie("hello-cookie"));
|
||||
bean.setSessionid(req.getSessionid(false));
|
||||
bean.setClientaddr(req.getRemoteAddr());
|
||||
bean.setUseragent(req.getHeader("User-Agent"));
|
||||
bean.setRescookie(req.getCookie("hello-cookie"));
|
||||
bean.setSessionid(req.getSessionid(false));
|
||||
Flipper flipper = req.getFlipper();
|
||||
Sheet<HelloEntity> result = service.queryHello(bean, flipper);
|
||||
resp.finishJson(result);
|
||||
@@ -105,10 +105,10 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
public void list(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
||||
HelloBean bean = req.getJsonParameter(HelloBean.class, "bean");
|
||||
bean.setClientaddr(req.getRemoteAddr());
|
||||
bean.setUseragent(req.getHeader("User-Agent"));
|
||||
bean.setRescookie(req.getCookie("hello-cookie"));
|
||||
bean.setSessionid(req.getSessionid(false));
|
||||
bean.setClientaddr(req.getRemoteAddr());
|
||||
bean.setUseragent(req.getHeader("User-Agent"));
|
||||
bean.setRescookie(req.getCookie("hello-cookie"));
|
||||
bean.setSessionid(req.getSessionid(false));
|
||||
List<HelloEntity> result = service.queryHello(bean);
|
||||
resp.finishJson(result);
|
||||
}
|
||||
@@ -122,12 +122,4 @@ public class _DynHelloRestServlet1 extends SimpleRestServlet {
|
||||
resp.finishJson(bean);
|
||||
}
|
||||
|
||||
@AuthIgnore
|
||||
@WebAction(url = "/hello/jsfind/")
|
||||
public void jsfind(HttpRequest req, HttpResponse resp) throws IOException {
|
||||
HelloService service = _servicemap == null ? _service : _servicemap.get(req.getHeader(Rest.REST_HEADER_RESOURCE_NAME, ""));
|
||||
int id = Integer.parseInt(req.getRequstURILastPath());
|
||||
HelloEntity bean = service.findHello(id);
|
||||
resp.finishJsResult("varhello", bean);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user