BeanUtil 操作Bean属性

来源:互联网 发布:log4j打印sql日志 编辑:程序博客网 时间:2024/05/22 09:48


简单的方法操作Bean属性


import javax.servlet.http.HttpServletRequest;

import org.apache.commons.beanutils.BeanUtils;

public class WebUtil {
 public static <T>T fillBean(HttpServletRequest request,Class<T> clazz){
  try {
   T t = clazz.newInstance();// 调用默认构造方法创建对象
   BeanUtils.populate(t, request.getParameterMap());
   return t;
  } catch (Exception e) {
   throw new RuntimeException(e);
  }
  
 }
}

0 0
原创粉丝点击