This commit is contained in:
@@ -120,8 +120,8 @@ public abstract class HttpBaseServlet extends HttpServlet {
|
||||
|
||||
/**
|
||||
* 配合 HttpBaseServlet 使用。
|
||||
* 当标记为 @HttpCacheable 的方法使用response.finish的参数将被缓存一定时间(默认值timeout=15秒)。
|
||||
* 通常情况下 @HttpCacheable 需要与 @AuthIgnore 一起使用,因为没有标记@AuthIgnore的方法一般输出的结果与当前用户信息有关。
|
||||
* 当标记为 @HttpCacheable 的方法使用response.finish的参数将被缓存一段时间(默认值timeout=15秒)。
|
||||
* 通常情况下 @HttpCacheable 需要与 @AuthIgnore 一起使用,没有标记@AuthIgnore的方法一般输出的结果与当前用户信息有关。
|
||||
*
|
||||
* <p>
|
||||
* 详情见: http://redkale.org
|
||||
|
||||
@@ -76,6 +76,7 @@ public final class Rest {
|
||||
final String restoutputDesc = Type.getDescriptor(RestOutput.class);
|
||||
final String attrDesc = Type.getDescriptor(org.redkale.util.Attribute.class);
|
||||
final String authDesc = Type.getDescriptor(HttpBaseServlet.AuthIgnore.class);
|
||||
final String cacheDesc = Type.getDescriptor(HttpBaseServlet.HttpCacheable.class);
|
||||
final String actionDesc = Type.getDescriptor(HttpBaseServlet.WebAction.class);
|
||||
final String webparamDesc = Type.getDescriptor(HttpBaseServlet.WebParam.class);
|
||||
final String sourcetypeDesc = Type.getDescriptor(HttpBaseServlet.ParamSourceType.class);
|
||||
@@ -207,6 +208,11 @@ public final class Rest {
|
||||
av0 = mv.visitAnnotation(authDesc, true);
|
||||
av0.visitEnd();
|
||||
}
|
||||
if (entry.cachetimeout > 0) { //设置 HttpCacheable
|
||||
av0 = mv.visitAnnotation(cacheDesc, true);
|
||||
av0.visit("timeout", entry.cachetimeout);
|
||||
av0.visitEnd();
|
||||
}
|
||||
|
||||
mv.visitVarInsn(ALOAD, 0);
|
||||
mv.visitFieldInsn(GETFIELD, newDynName, REST_SERVICEMAP_FIELD_NAME, "Ljava/util/Map;");
|
||||
@@ -340,14 +346,16 @@ public final class Rest {
|
||||
av3.visitEnd();
|
||||
}
|
||||
java.lang.reflect.Type grt = method.getGenericReturnType();
|
||||
av0.visit("result", grt == returnType ? returnType.getName(): String.valueOf(grt));
|
||||
av0.visit("result", grt == returnType ? returnType.getName() : String.valueOf(grt));
|
||||
|
||||
av0.visitEnd();
|
||||
actionMap.put("url", url);
|
||||
actionMap.put("auth", entry.auth);
|
||||
actionMap.put("cachetimeout", entry.cachetimeout);
|
||||
actionMap.put("actionid", entry.actionid);
|
||||
actionMap.put("comment", entry.comment);
|
||||
actionMap.put("methods", entry.methods);
|
||||
actionMap.put("result", grt == returnType ? returnType.getName(): String.valueOf(grt));
|
||||
actionMap.put("result", grt == returnType ? returnType.getName() : String.valueOf(grt));
|
||||
}
|
||||
|
||||
List<Map<String, Object>> paramMaps = new ArrayList<>();
|
||||
@@ -1025,7 +1033,8 @@ public final class Rest {
|
||||
this.methods = mapping.methods();
|
||||
this.auth = mapping.auth();
|
||||
this.actionid = mapping.actionid();
|
||||
this.contentType = mapping.contentType();
|
||||
this.cachetimeout = mapping.cachetimeout();
|
||||
//this.contentType = mapping.contentType();
|
||||
this.comment = mapping.comment();
|
||||
this.jsvar = mapping.jsvar();
|
||||
}
|
||||
@@ -1044,8 +1053,9 @@ public final class Rest {
|
||||
|
||||
public final int actionid;
|
||||
|
||||
public final String contentType;
|
||||
public final int cachetimeout;
|
||||
|
||||
//public final String contentType;
|
||||
public final String jsvar;
|
||||
|
||||
@RestMapping()
|
||||
|
||||
@@ -41,9 +41,11 @@ public @interface RestMapping {
|
||||
|
||||
int actionid() default 0; //操作ID值,鉴权时用到, 对应@WebAction.actionid
|
||||
|
||||
int cachetimeout() default 0; // 结果缓存的秒数, 为0表示不缓存
|
||||
|
||||
String[] methods() default {};//允许方法(不区分大小写),如:GET/POST/PUT,为空表示允许所有方法, 对应@WebAction.methods
|
||||
|
||||
String contentType() default ""; //设置Response的ContentType 默认值为 text/plain; charset=utf-8
|
||||
//String contentType() default ""; //设置Response的ContentType 默认值为 text/plain; charset=utf-8
|
||||
|
||||
String jsvar() default ""; //以application/javascript输出对象是指明js的对象名,该值存在时则忽略contentType()的值
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user