使命召唤9 黑屏-如何关闭空间
2023年4月3日发(作者:mp3转cda格式)
beanutil批量copy,使⽤BeanUtils在bean之间复制具有不同名
称的属性
IwouldliketocopythepropertyvaluesfromClassAtoClassBwithBeanUtilswhichhassamefieldsbutwithdifferent
ssibletoprovideamapofpropertynametodifferentName,agetodifferentAgeetc.,andachievethe
copying?IaminterestedtoknowifthisispossiblebyanymeansusingonlyApacheCommonsutilities(notanyothertools).
classClassA{
privateStringname;
privateIntegerage;
...//SetterandGettermethods
}
classClassB{
privateStringdifferentName;
privateIntegerdifferentAge;
...//SetterandGettermethodsfortheprivatefields
}
解决⽅案
ApacheCommonsBeanUtilshasmethodthemethodpopulate(Objectbean,
Mapproperties)acceptsamaptopopulatetheBeanwithkeyvaluepairs.
NOTE:IjustsawthelimitationonApache-Commons-butitmaystillbeusefulforotherpeopleandasfarasIam
concernedthebettersolution.
yourcaseyoucanspecifysourceandtarget
Membersinanxmlmappingfile.
更多推荐
beanutils populate
发布评论