把request对象中的请求参数封装到bean中的工具类

public class WebUtils {

//把request对象中的请求参数封装到bean中
public static T request2Bean(HttpServletRequest request,Class clazz){
try{
T bean = clazz.newInstance();
//username=aa password=bb [email protected]
Enumeration e = request.getParameterNames(); 
while(e.hasMoreElements()){
String name = (String) e.nextElement();  //username=aaa password=123
String value = request.getParameter(name);
BeanUtils.setProperty(bean, name, value);
}
return bean;
}catch (Exception e) {
throw new RuntimeException(e);
}
}
}

转载于:https://www.cnblogs.com/toge/p/6114680.html

你可能感兴趣的:(把request对象中的请求参数封装到bean中的工具类)