我有一个方法:
def nameToCode(nameStr){
def ret = resortService.getResort("all")
//this gets like 180 objects with various properties like name, code, etc.
def resorts = [name: ret.prName, code: ret.prProductIndex]
def code = resorts.findByName(nameStr) //this doesn't work
println(code)
return code
}
我正在尝试调用此方法并向其发送一个名称。然后它应该在地图中找到名称,如果它发现它应该返回名称的代码。这应该是简单的,但我一直在搜索,无法弄清楚如何做到这一点。我会感激任何帮助。感谢
答案 0 :(得分:2)
您在标准地图上使用gorm方法: 而不是:
def resorts = [name: ret.prName, code: ret.prProductIndex]
def code = resorts.findByName(nameStr) //this doesn't work
尝试:
def resorts = [name: ret.prName, code: ret.prProductIndex]
def code = resorts.findAll{name==nameStr}