diff options
Diffstat (limited to 'juick-spring-www/src/main/java/com/juick/www/helpers')
-rw-r--r-- | juick-spring-www/src/main/java/com/juick/www/helpers/QueryString.java | 14 | ||||
-rw-r--r-- | juick-spring-www/src/main/java/com/juick/www/helpers/QueryStringResolver.java | 31 |
2 files changed, 45 insertions, 0 deletions
diff --git a/juick-spring-www/src/main/java/com/juick/www/helpers/QueryString.java b/juick-spring-www/src/main/java/com/juick/www/helpers/QueryString.java new file mode 100644 index 000000000..0eb6c76fe --- /dev/null +++ b/juick-spring-www/src/main/java/com/juick/www/helpers/QueryString.java @@ -0,0 +1,14 @@ +package com.juick.www.helpers; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Created by vt on 22/03/16. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.PARAMETER) +public @interface QueryString { +}
\ No newline at end of file diff --git a/juick-spring-www/src/main/java/com/juick/www/helpers/QueryStringResolver.java b/juick-spring-www/src/main/java/com/juick/www/helpers/QueryStringResolver.java new file mode 100644 index 000000000..812c44979 --- /dev/null +++ b/juick-spring-www/src/main/java/com/juick/www/helpers/QueryStringResolver.java @@ -0,0 +1,31 @@ +package com.juick.www.helpers; + +import org.springframework.core.MethodParameter; +import org.springframework.web.bind.support.WebDataBinderFactory; +import org.springframework.web.context.request.NativeWebRequest; +import org.springframework.web.method.support.HandlerMethodArgumentResolver; +import org.springframework.web.method.support.ModelAndViewContainer; + +import javax.servlet.http.HttpServletRequest; +import java.lang.annotation.Annotation; +import java.util.Optional; + +public class QueryStringResolver implements HandlerMethodArgumentResolver { + @Override + public boolean supportsParameter(MethodParameter parameter) { + Annotation[] parameterAnnotations = parameter.getParameterAnnotations(); + for (Annotation parameterAnnotation : parameterAnnotations) { + if (QueryString.class.isInstance(parameterAnnotation)) { + return true; + } + } + + return false; + } + + @Override + public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { + HttpServletRequest request = webRequest.getNativeRequest(HttpServletRequest.class); + return Optional.ofNullable(request.getQueryString()); + } +}
\ No newline at end of file |