HttpServletRequest获取REST风格参数
Object attributeObject = request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE); Map<String, Object> restParamsMap = typeConversionMap(attributeObject,String.class,Object.class); // 获取Token String token = String.valueOf(restParamsMap.get("token"));
public <K, V> Map<K, V> typeConversionMap(Object obj, Class<K> tClass, Class<V> vClass) { HashMap<K, V> result = new HashMap<>(); if (obj instanceof Map<?, ?>) { Map<?, ?> map = (Map<?, ?>) (obj); for (Map.Entry<?, ?> entry : map.entrySet()) { result.put(tClass.cast(entry.getKey()), vClass.cast(entry.getValue())); } } return result; }