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()); } }