2009-03-05 15 views
1

BeanUtils copyProperties, kutudan çıktığında, Boolean nesne özelliklerinden boolean ilkel özelliklere kopyalama yapmıyor gibi görünüyor.Boole'den Boole'ye kopyalamak için BeanUtils copyProperties'i nasıl kullanabilirim?

Bunu işlemek için bir dönüştürücü oluşturabileceğimi ve kaydettirebileceğimi düşündüm, ancak bu işe yaramadı. Yani

, nasıl sınıf Hedefe sınıf Kaynaktan özelliklerini kopyalamak için beanutils kullanabilirsiniz burada:

public class Destination { 

    private boolean property; 

    public boolean isProperty() { 
     return property; 
    } 

    public void setProperty(boolean property) { 
     this.property = property; 
    } 
} 


public class Source{ 

    private Boolean property; 

    public Boolean getProperty() { 
     return property; 
    } 

    public void setProperty(Boolean property) { 
     this.property = property; 
    } 
} 
+0

ben Şimdi bunun üzerinde sıkışmış. Eğer bunu yapabildiysen bir cevap 'taşıyıcı' ekleyin :) –

cevap

0

Aslında tersi geçerli:

public static void main(String[] args) throws Exception { 
    Source d = new Source(); 
    d.setProperty(Boolean.TRUE); 
    BeanMap beanMap = new BeanMap(d); 

    Destination s = new Destination(); 
    BeanUtils.populate(s, beanMap); 
    System.out.println("s.getProperty()=" + s.isProperty()); 
} 
0
public class Destination { 
    private boolean property; 

    // code getProperty() instead 
    public boolean isProperty() { 
     return property; 
    } 

    public void setProperty(boolean property) { 
     this.property = property; 
    } 
} 
1
try creating both 
/*by default beanutils copyproperties looks for below method if you use either apache or spring flavour of beanutils. 
always prefer using apache 1.9.2 (fixed many bugs) but bit slow compared with spring beanutils.*/ 
public Boolean getProperty() { 
     return property; 
    } 
//which is used by some frameworks 
public Boolean isProperty() { 
     return property; 
    } 
+0

biz ConvertUtils.register (yeni DateConverter (null), java.util.Date.class) gibi apache beanutils kullandığımızda dönüştürücü kullanmanız gerekir; – RamPrakash

İlgili konular