在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';
答案 0 :(得分:2)
要复制原始属性,您可以使用properties
属性,如下所示:
def original = Musicians.get(id)
def copy = new Musicians(original.properties)
copy.firstName = 'Example'
copy.lastName = 'Musician'
不需要分号;)