spring: pyproperties将一个对象的数据塞入到另一个对象中(合并对象)...

阅读: 评论:0

spring: pyproperties将一个对象的数据塞入到另一个对象中(合并对象)...

spring: pyproperties将一个对象的数据塞入到另一个对象中(合并对象)...

spring: pyproperties将一个对象的数据塞入到另一个对象中(合并对象)

它的出现原因: BeanUtils提供对Java反射和自省API的包装。其主要目的是利用反射机制对JavaBean的属性进行处理。我们知道,一个JavaBean通常包含了大量的属性,很多情况下,对JavaBean的处理导致大量get/set代码堆积,增加了代码长度和阅读代码的难度。

 

我有一个Category分类表对象,和一个ProductInfo商品表对象

我需要的数据格式是(以分类作为基数,分类下面有多条帖子):

data:[{"cid":1,"name":"灌水","theads":[{"id":1,"cid":1,"name":"有喜欢这歌的吗?""time":"2018-12-12 18:25" },{"id":1,"cid":1,"name":"有喜欢这歌的吗?""time":"2018-12-12 18:25" }]} ,{"cid":2,"name":"文学","theads":[{"id":18,"cid":2,"name":"徐志摩的诗""time":"2018-12-12 18:25" },{"id":21,"cid":2,"name":"鲁迅的散文""time":"2018-12-12 18:25" }]}   
]

  

代码如下

 ResultVO resultVO = new ResultVO();//ProductVO productVO = new ProductVO();//List<ProductInfoVO> productInfoVOList  = new ArrayList<ProductInfoVO>();//productVO.setProductInfoVOList(productInfoVOList);//resultVO.setData(productVO);//查询商品List<ProductInfo> productInfoList = product.findAll();//查询商品类目(一次性读完)//传统方法// List<Integer> categoryTypeList = new ArrayList<>();//for (ProductInfo productInfo: productInfoList)// {//    categoryTypeList.CategoryType());//}//java8-lambda方法List<Integer> categoryTypeList = productInfoList.stream().map(e -> e.getCategoryType()).List());List<ProductCategory> CategoryList = category.findByCategoryTypeIn(categoryTypeList);//拼合数据for (ProductCategory category: CategoryList){//productCategoryProductVO productVO = new ProductVO();productVO.CategoryType());productVO.CategoryName());//productInfoList<ProductInfoVO> productInfoVOList = new ArrayList<>();for (ProductInfo productInfo : productInfoList){CategoryType().CategoryType())){//老方法:ProductInfoVO productInfoVO = new ProductInfoVO();productInfoVO.ProductId());productInfoVO.ProductName());productInfoVOList.add(productInfoVO);//新方法:将productInfo属性复制到productInfoVO1中//pypropertiesProductInfoVO productInfoVO1 = new ProductInfoVO();pyProperties(productInfo, productInfoVO1);productInfoVOList.add(productInfoVO1);}}productVO.setProductInfoVOList(productInfoVOList);}return resultVO;//return "list";

  

 

转载于:.html

本文发布于:2024-02-02 15:43:04,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170685978244786.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:对象   象中   数据   spring   beanutils
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23