2016-04-07 55 views
0

在Grails中,有沒有一種方法可以使用現有行來實例化新行?或者,我是否需要循環訪問屬性並設置它們?Grails:如何複製/克隆/複製行實例

def original=Musicians.get(id); 

//want to start with all the same values as original and then modify 
def copy=new Musicians(); 
copy.firstName="Example"; 
copy.lastName='Musician'; 

回答

2

要複製原來的屬性,你可以使用properties屬性,比如:需要

def original = Musicians.get(id) 
def copy = new Musicians(original.properties) 

copy.firstName = 'Example' 
copy.lastName = 'Musician' 

沒有分號;)