BeanUtils.populate的作用

首先,它是 org.apache.commons.beanutils.BeanUtils包中的一个方法。
方法的作用:用来将一些 key-value 的值(例如 hashmap)映射到 bean 中的属性。

servlet中有这样的使用:
先定义form表单内容的Info对象(当然你要先写一个bean,这个bean中包含form表单中各个对象的属性)
    FormBean xxxbean = new FormBean();  (这是一个javabean)
—>BeanUtils.populate(xxxbean, request.getParameterMap());(调用包中方法映射)

映射的过程就是将页面中的内容先用request获得,然后再将之转换为Map(这里用request.getParameterMap())
最后使用BeanUtils.populate(info,map)方法将页面各个属性映射到bean中。之后我们就可以这样使用xxxbean.getXxxx()来取值了。

原文地址:https://www.cnblogs.com/dayInAndOut/p/3822499.html