BeanUtils.populate( Object bean, Map properties ),

BeanUtils.populate( Object bean, Map properties )

先遍历map<k,v>中的k 如果k和bean相同 就将v的值赋给bean

补充:map中的数据映射到JavaBean中的get和set方法中(封装数据到JavaBean中)。之后取值就直接从JavaBean中的get和set方法中取值就可以了。

使用BeanUtils.populate(info,map)方法将页面各个属性映射到bean中 我们就可以这样使用bean.getXxxx() bean.setXxxx()。

就如结合下面的例子:BeanUtils.populate(item, map);及时将map中的值映射到item中的getXxx setXxx方法中,因而就对map中的数据封装到了orderItem中去l

例子:

                       //获得每一个订单的oid
			 String oid= order.getOid();
			 //查询该订单的所有订单项--maplist封装的是多个订单项和订单项中的商品信息
			 List<Map<String, Object>> maplist=service.findAllOrderItemByOid(oid);
			 //将maplist转换为list<OrderItem> orderItems
			 for(Map<String,Object> map:maplist){
				 
				  try {
					//从map中取出count subtotal 封装到OrderItem
					  orderItem item = new orderItem();
					 // item.setCount(Integer.parseInt(map.get("count").toString()));
					BeanUtils.populate(item, map);
					 //从map中取出pimage pname shop_price 封装到Product中
					 Product product=new Product();
					 BeanUtils.populate(product, map);

					 //将product封装到OrderItem
					 item.setProduct(product);
					 //将orderItem封装到order中的orderItemList中
					 order.getOrderItems().add(item);

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值