beanutils的使用

在项目进行中,使用到beanutils时发现1.9.X以上版本搭配logging搭配使用用不了,实在搞不明白。----stackoverflow提问吧

BeanUtils工具由Apache软件基金组织编写,提供给我们使用,主要解决的问题是:把对象的属性数据封装到对象中。

(1)导包

commons-beanutils-1.x.x.jar

commons-logging.jar

 

BeanUtils.populate(bean,Map)//注入 

替代了:

String username = request.getParameter("username");
String password = request.getParameter("password");
String email = request.getParameter("email");

........

自定义数据类型使用BeanUtils工具时,本身必须具备getter和setter方法,因为BeanUtils工具本身也是一种内省的实现方法,所以也是借助于底层的getter和setter方法进行转换的。

 经过使用该工具后可以动态获取jsp中的相关参数,避免了单个读取的繁琐。

posted @ 2017-06-21 17:20  lamsey16  阅读(152)  评论(0编辑  收藏  举报