现在的位置: 首页 > 综合 > 正文

把request中的所有键值赋到bean

2013年12月08日 ⁄ 综合 ⁄ 共 559字 ⁄ 字号 评论关闭

/**
  * 把request中的所有键值赋到bean
  *
  * @throws InvocationTargetException
  * @throws IllegalAccessException
  */
 @SuppressWarnings("unchecked")
 public static void populateReqBean(Object bean, HttpServletRequest request) {

  HashMap map = new HashMap();
  Enumeration names = request.getParameterNames();
  while (names.hasMoreElements()) {
   String name = (String) names.nextElement();
   map.put(name, request.getParameterValues(name));
  }
  try {
   BeanUtils.populate(bean, map);
  } catch (IllegalAccessException e) {

   e.printStackTrace();
  } catch (InvocationTargetException e) {

   e.printStackTrace();
  }

 } 

抱歉!评论已关闭.