HttpServletRequest转Map

HttpServletRequest转Map,第1张

HttpServletRequest转Map HttpServletRequest对象转Map
package com.tianyi.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("user")
public class UserController {

    @GetMapping("/test")
    public Map testDemo(HttpServletRequest request){
        
        Map map = this.getMap(request);

        return map;
    }

    
    public Map getMap(HttpServletRequest request) {
        Map map = new HashMap();
        
        Enumeration pNames = request.getParameterNames();
        while (pNames.hasMoreElements()) {
            String name = (String) pNames.nextElement();
            String value = request.getParameter(name);

            if (request.getParameter(name) != null) {
                map.put(name,value);
            }

            
            String[] values = request.getParameterValues("username");
            for(String StringValue:values){
                System.out.println(StringValue);
            }

            
        }
        return map;
    }

}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5597662.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存