1.前言


最近在做一个javaweb项目练练手,涉及到把jsp页面中表单的内容存到数据库,和request.getParameterMap配合使用可以将jsp页面表单的数据转化为bean对象。


2.介绍


BeanUtils位于org.apache.commons.beanutils.BeanUtils下面,其方法populate的作用解释如下:

完整方法:

BeanUtils.populate( Object bean, Map properties ),

这个方法会遍历map<key, value>中的key,如果bean中有这个属性,就把这个key对应的value值赋给bean的属性。


3.使用


在获取jsp页面中表单数据的时候,刚好可以使用request.getParameterMap得到表单数据的map集合

Map<String, String[]> map = request.getParameterMap();

配合BeanUtils.populate使用,将map集合转化为bean对象

BeanUtils.populate(user,map);




相关文章:

  • 2022-12-23
  • 2021-06-21
  • 2021-08-03
  • 2022-01-20
  • 2021-12-09
  • 2021-11-27
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-22
  • 2021-06-20
  • 2022-12-23
  • 2019-09-02
相关资源
相似解决方案