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

 

posted @ 2021-11-11 15:39  为牛马者,背负前行  阅读(257)  评论(0编辑  收藏  举报

如果本页面列出的内容侵犯了您的权益,请告知。
知识共享许可协议
996.icu