如http://n4.nabble.com/Grails-Data-Binding-for-One-To-Many-Relationships-with-REST-tp1754571p1754571.html所述,我試圖自動綁定我的REST數據。Grails數據綁定中的黑魔法?
我現在明白了一個-to-many關聯所需的數據綁定必須有很多副作用的IDS,如清單地圖:
[propName: propValue, manyAssoc: [1, 2]]
但是,我越來越這個例外
Executing action [save] of controller [com.example.DomainName] caused exception: org.springframework.orm.hibernate3.HibernateSystemException: IllegalArgumentException occurred calling getter of com.example.DomainName.id; nested exception is org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.example.DomainName.id
但是,即使是weirder是爲控制器生成的更新操作。在那裏,我們有數據綁定這樣的:
domainObjectInstance.properties = params['domainObject']
但是,這真的是個奇怪的東西,則params [「domainObject的」]爲空!它是null,因爲所有的domainObject字段都直接在params映射本身中傳遞。如果我將上述行更改爲
domainObjectInstance.properties = null
domainObject仍然更新!爲什麼會出現這種情況,更重要的是,我怎麼能自動綁定我的傳入XML如果它以這種格式(問題是一個-to-many關聯):
<product>
<name>Table</name>
<brand id="1" />
<categories>
<category id="1" />
<category id="2" />
</categories>
</product>