Parcourir la source

新增jsonp,aop注解支持

周浩 il y a 9 ans
Parent
commit
db2d2140bb

+ 26 - 0
hsweb-web-core/src/main/java/org/hsweb/web/core/authorize/annotation/AopJsonpSupport.java

@@ -0,0 +1,26 @@
+package org.hsweb.web.core.authorize.annotation;
+
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Before;
+import org.hsweb.web.core.jsonp.Jsonp;
+import org.hsweb.web.core.utils.ThreadLocalUtils;
+import org.hsweb.web.core.utils.WebUtil;
+import org.springframework.core.annotation.Order;
+import org.springframework.stereotype.Component;
+import org.webbuilder.utils.common.StringUtils;
+
+/**
+ * Created by zhouhao on 16-5-26.
+ */
+@Aspect
+@Order
+@Component
+public class AopJsonpSupport {
+    @Before(value = "@annotation(jsonp)")
+    public void around(Jsonp jsonp) throws Throwable {
+        String callback = WebUtil.getHttpServletRequest().getParameter(jsonp.value());
+        if (!StringUtils.isNullOrEmpty(callback)) {
+            ThreadLocalUtils.put("jsonp-callback", callback);
+        }
+    }
+}