CopyUtil参数枚举

xiaoxiao2021-02-28  39

package com.chen.util; import javax.servlet.http.HttpServletRequest; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; public class CopyUtil { public static Map<String, Object> copyToMap(HttpServletRequest request){ Map<String, Object> map = new HashMap<String, Object>(); Enumeration<String> enumeration = request.getParameterNames(); while (enumeration.hasMoreElements()) { String name = (String) enumeration.nextElement(); Object value = null; String[] arr = request.getParameterValues(name); if(arr != null && arr.length == 1){ if(StringUtil.isNotBlank(arr[0])){ value = arr[0]; } } if(arr != null && arr.length > 1){ value = arr; } if (value!=null) { map.put(name, value); } } return map; } }

使用:

import javax.servlet.http.HttpServletRequest; @Controller public class HelloController{ @RequestMapping("hi") @ResponseBody public Map<String,Object> addPerimeterProtection(HttpServletRequest request){ Map<String,Object> resultMap = new HashMap<String,Object>(); String serviceId = request.getParameter("serviceId"); String id= request.getParameter("id"); } }
转载请注明原文地址: https://www.6miu.com/read-2350260.html

最新回复(0)