如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>