BeanUtils.populate的作用

谁都会走 提交于 2020-01-31 18:19:12

BeanUtils.populate的作用

首先,它是在org.apache.commons.beanutils.BeanUtils包中的一个方法。
方法的作用:用来将一些 key-value 的值(例如 hashmap)映射到 bean 中的属性。
 
servlet中有这样的使用:
先定义form表单内容的Info对象(当然你要先写一个bean,这个bean中包含form表单中各个对象的属性)
    InsuranceInfo info = new InsuranceInfo();  (这是一个javabean)
    BeanUtilities.populateBean(info, request);
——> populateBean(info, request.getParameterMap());(先将request内容转为Map类型)
——>BeanUtils.populate(info, propertyMap);(调用包中方法映射)
 
映射的过程就是将页面中的内容先用request获得,然后再将之转换为Map(这里用request.getParameterMap())
最后使用BeanUtils.populate(info,map)方法将页面各个属性映射到bean中。之后我们就可以这样使用bean.getXxxx()来取值了。
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!