Spring time on the use of recording in BeanUtils

1. Description of the problem: the front and rear ends of the FBI during the day, I found pictures of goods can not be shown;

 

2. The investigation process : see the browser console, call interface found on the data returned by the image field not return data;

          Then, the unit test ran at Dao layer, normal data out from the database;

        That is, the basic code data conversion confirmation lost turn, hit the Debug, is really the case, the conversion from the BeanUtils.copyProperties (productInfo, productInfoVO) at;

 

3. Cause: The value of the picture field failed to correctly copy the past, because the two Bean's icon (picture) does not correspond to the fields;

 

4. Hands

             log.info ( "compare two objects: {}", productInfo.getProductIcon () == productInfoVO.getProductIcon ()); 
                    log.info ( "productInfo the hashCode: {}" ., productInfo.getProductIcon () the hashCode ( )); 
                    log.info ( "productInfoVO the hashcode: {}", productInfoVO.getProductIcon ( ) hashCode ());.

 

 icon is of type String field, here shown as the same object, it is a shallow copy;

 

Bean fields and more fields converted to less Bean

BeanUtils.copyProperties (productinfo, productInfoVO);

 

 

Try again next turn

BeanUtils.copyProperties (productInfoVO, productinfo);

 

 

5. Summary using BeanUtils.copyProperties () and pay attention:

  BeanUtils.copyProperties (productInfo, productInfoVO) action: the value of a copy of the entity to another entity, avoiding the large number of Bean get, set;

  (1) copy relationship: the value of the parameter is copied to the front of the back of the parameters, i.e., to copy productInfo productInfoVO; apache has a BeanUtils, the opposite order;

  (2) field corresponds: to the same field, or will fail assignment;

  (3) where a shallow copy

 

 

 

 

Guess you like

Origin www.cnblogs.com/inu6/p/11816428.html