0
我想創建更新實體的通用代碼。這是我想出:合併後爲什麼實體id增加? [Grails]
def update(id, Object updatedEntity) {
def entity = findById(id)
if (entity) {
updatedEntity.id = id
def mergedEntity = updatedEntity.merge()
if (mergedEntity) {
return mergedEntity
} else {
throw new ValidationException("Cannot update.", mergedEntity.errors)
}
} else {
throw new IllegalArgumentException("No ${domainClass.getSimpleName()} with id=${id} found.")
}
}
爲什麼mergedEntity
總是遞增id
值(我的意思是,如果updatedEntity.id = 1
,然後mergedEntity.id
將2.我怎樣才能解決這個問題
更新實體是獨立實體?我認爲你需要閱讀什麼合併實際用於。 http://grails.org/doc/latest/ref/Domain%20Classes/merge.html – Gregg
Grails是一種動態語言,已經有很多內置的「通用代碼」來處理這樣的事情。你能解釋你想做什麼,爲什麼? –
@Gregg:是,updatedEntity已分離。 – Roman