From e55d4d8a78bf5c28049f0291789179f2c45b6c0a Mon Sep 17 00:00:00 2001 From: Redkale <22250530@qq.com> Date: Sat, 28 Apr 2018 19:32:02 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8D=E5=90=AB#=E4=B8=94=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E4=B8=8D=E8=B6=85=E8=BF=876=E4=B8=AA=E7=9A=84RestService?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2RestServlet=E9=87=87=E7=94=A8=E6=9E=9A?= =?UTF-8?q?=E4=B8=BE=E6=96=B9=E5=BC=8F=E5=88=97=E5=87=BA@WebServlet.value?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/org/redkale/net/http/Rest.java | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/org/redkale/net/http/Rest.java b/src/org/redkale/net/http/Rest.java index 58d0a33b3..1544c17b7 100644 --- a/src/org/redkale/net/http/Rest.java +++ b/src/org/redkale/net/http/Rest.java @@ -779,7 +779,14 @@ public final class Rest { av0 = cw.visitAnnotation(webServletDesc, true); { AnnotationVisitor av1 = av0.visitArray("value"); - if (defmodulename.isEmpty()) { + boolean pound = false; + for (MappingEntry entry : entrys) { + if (entry.existsPound) { + pound = true; + break; + } + } + if (defmodulename.isEmpty() || (!pound && entrys.size() <= 6)) { for (MappingEntry entry : entrys) { String suburl = (catalog.isEmpty() ? "/" : ("/" + catalog + "/")) + (defmodulename.isEmpty() ? "" : (defmodulename + "/")) + entry.name; urlpath += "," + suburl; @@ -1821,6 +1828,22 @@ public final class Rest { this.actionid = mapping.actionid(); this.cacheseconds = mapping.cacheseconds(); this.comment = mapping.comment(); + boolean pound = false; + Parameter[] params = method.getParameters(); + for (Parameter param : params) { + RestParam rp = param.getAnnotation(RestParam.class); + if (rp != null && !rp.name().isEmpty() && rp.name().charAt(0) == '#') { + pound = true; + break; + } + } + if (!pound && params.length == 1) { + Class ptype = method.getParameterTypes()[0]; + if (this.name.startsWith("find") || this.name.startsWith("delete")) { + if (ptype.isPrimitive() || ptype == String.class) pound = true; + } + } + this.existsPound = pound; } public final int methodidx; // _paramtypes 的下标,从0开始 @@ -1841,6 +1864,8 @@ public final class Rest { public final int cacheseconds; + public final boolean existsPound; //是否包含#的参数 + @RestMapping() void mapping() { //用于获取Mapping 默认值 }