package com.hhh.framework.tools.utils;
import org.apache.commons.beanutils.BeanUtils;
import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 用于解析HttpServletRequest中参数的公用方法类
*
* @author
*/
public final class RequestResolver {
/**
* 从request中获取参数,组装为指定类型的对象
*
* @param request : 前台请求
* @param objClass : 返回对象的类
* @param <T> : 泛型标识
* @return : 指定类型对象的list
* @throws IllegalAccessException : 反射创建对象时抛出异常
* @throws InstantiationException : 反射创建对象时抛出异常
* @throws InvocationTargetException : 反射赋值时抛出异常
* @throws NoSuchFieldException : 获取字段失败的异常
*/
public static <T> List<T> getListParams(HttpServletRequest request, Class<T> objClass)
throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchFieldException {
List<T> objList = null;
List<Field> fields = getUsedProperties(request, objClass);
String className = objClass.getSimpleName();
if (!fields.isEmpty()) {
int valueLength = getValueLength(request, className, fields);
objList = new ArrayList<T>(valueLength);
T obj;
Object fieldValue = null;
String fieldName = null;
if (valueLength == 1) { //仅有一个对应
obj = objClass.newInstance();
for (Field fieldInfo : fields) {
fieldName = fieldInfo.getName();
fieldValue = getFieldValue(fieldInfo, request.getParameter(className + "." + fieldName)
用于解析HttpServletRequest中参数的公用方法类
最新推荐文章于 2023-04-01 05:12:39 发布