Java DataBindingLazyMetaPropertyMap中的此实现不支持方法remove(对象o)

Java DataBindingLazyMetaPropertyMap中的此实现不支持方法remove(对象o),java,dictionary,grails,Java,Dictionary,Grails,在grails中的DataBindingLazyMetaPropertyMap中,“put,get”方法起作用,但remove不起作用。有人对此有什么想法和解决办法吗 我的代码: def mapObj = [age:"20",location:"earth"] mapObj.put("name","test"); // inserts the data in mapObj with key = "name" mapObj.get("name"); // returns

在grails中的DataBindingLazyMetaPropertyMap中,“put,get”方法起作用,但remove不起作用。有人对此有什么想法和解决办法吗

我的代码:

   def mapObj = [age:"20",location:"earth"] 
   mapObj.put("name","test");  // inserts the data in mapObj with key = "name" 

   mapObj.get("name"); // returns the value of the mapObj with key = "name" 

   mapObj.remove("name"); // removes the key value pair from mapObj with key = "name"
mapObj的类是java.util.LinkedHashMap

到目前为止,一切都很顺利

 mapObj = domainObj.properties
将mapObj的类转换为DataBindingLazyMetaPropertyMap

mapObj.put("name","test"); // inserts the data in mapObj with key "name" 

mapObj.get("name"); // returns the value of the mapObj with key "name" 

mapObj.remove("name"); // returns error Method remove(Object o) is not supported by this implementation

当您不确定时,请检查它是什么数据类型:

mapObj = domainObj.properties
println "object is now ${mapObj.getClass()}"
在groovy中,有时事物会变成真实的对象,因此您需要复制它。将上述内容与示例进行比较:

mapObj = domainObj.properties.clone()
e2A

所以你的评论表明它不能被克隆

请查看此链接

http://docs.grails.org/latest/ref/Domain%20Classes/properties.html

def b = new Book(title: "The Shining")
b.properties = params
b.save()
我从未在哪里使用属性查询/获取域对象映射始终设置其值

您需要编写一个HQL查询,该查询执行一个
从blah中选择一个新映射(e.a为a,e.b为b),以返回一个平面映射

或者在域类中引入一个新函数

Class Example
  String a
  String b

def loadValues() {
  Map map = [:]
  map.a=this.a
  map.b=this.ba
  return map
 }
}
现在打电话

mapObj = domainObj.loadValues()
它返回对象的平面贴图

另请参阅
实现可克隆性

使用.clone()函数导致CloneNotSupportedException。