1、导入架包
commons-beanutils-20030211.134440.jar
commons-logging-1.1.3.jar
// Class<T> beanClass可以接受任何类型的javaBean,使用泛型调用者不用进行强转
public <T> T requestToBean(HttpServletRequest request, Class<T> beanClass) {
try {
// 创建封装数据的bean
T bean = beanClass.newInstance();
Map map = request.getParameterMap();
BeanUtils.populate(bean, map);
return bean;
} catch (Exception e) {
throw new RuntimeException(e);
}
}