请求参数

Posted cabinet

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了请求参数相关的知识,希望对你有一定的参考价值。

public class PackData extends HashMap implements Map{

private static final long serialVersionUID = 1L;

Map map = null;
HttpServletRequest request;
public PackData(HttpServletRequest request){
	this.request = request;
	Map properties = request.getParameterMap();
	Map returnMap = new HashMap();
	Iterator entries = properties.entrySet().iterator();
	Entry entry;
	String name = "";
	String value = "";
	while (entries.hasNext()) {
		entry = (Entry) entries.next();
		name = (String) entry.getKey();
		Object valueObj = entry.getValue();
		if(null == valueObj){
			value = "";
		}else if(valueObj instanceof String[]){
			String[] values = (String[])valueObj;
			for(int i=0;i<values.length;i++){
				value = values[i] + ",";
			}
			value = value.substring(0, value.length()-1);
		}else{
			value = valueObj.toString();
		}
		returnMap.put(name, value);
	}
	if(returnMap.containsKey("page")&&returnMap.containsKey("rows")){
		Integer page = Integer.parseInt(returnMap.get("page").toString());
		Integer rows = Integer.parseInt(returnMap.get("rows").toString());
		Integer start = (page==0?0:page-1)*rows;
		Integer end = rows;
		returnMap.put("start", start);
		returnMap.put("end", end);
	}
	map = returnMap;
}

public PackData() {
	map = new HashMap();
}

public PackData(Map map) {
	this.map = map;
}

以上是关于请求参数的主要内容,如果未能解决你的问题,请参考以下文章

VSCode自定义代码片段14——Vue的axios网络请求封装

VSCode自定义代码片段14——Vue的axios网络请求封装

Python 向 Postman 请求代码片段

jQuery高级Ajax

片段(Java) | 机试题+算法思路+考点+代码解析 2023

xml Eclipse模板(代码片段)检查参数并最终抛出IllegalArgumentException