所以,一直试图用grails进行搜索,并且无法弄清楚最新情况。
该应用有两个域,一个国家地图(称为国家/地区),第二个是regstat,其中包含每个国家/地区的数据。 我设置它以便国家有许多regstat,regstat属于国家。 (最后粘贴了这个定义)。因此,尝试拨打电话,根据国家/地区和reg获取regstat条目。
def countdata(String sn, String regsel) {
def cpp = Regstat.where {
domain { countryiso == sn } && reg == regsel
}
render cpp as JSON
}
给我以下错误消息。
/GenMap/getcountry/countdata
Class
groovy.lang.MissingMethodException
Message
No signature of method: grails.gorm.DetachedCriteria.domain() is applicable for argument types: (genmap.GetcountryController$_countdata_closure1_closure10_closure11) values: [genmap.GetcountryController$_countdata_closure1_closure10_closure11@5dbfaacf] Possible solutions: min(), join(java.lang.String), min(java.lang.String), join(java.lang.String), min(groovy.lang.Closure), min(java.util.Comparator)
我也尝试过使用国家/地区
def countdata(String sn, String regsel) {
def cpp = Regstat.where {
country { countryiso == sn } && reg == regsel
}
render cpp as JSON
}
这给了我以下错误消息(在JSON Web返回中)
{"alias":null,"async":{"decorators":[{"class":"com.sun.proxy.$Proxy40"}],"gormOperations":{"_ref":"..","class":"grails.gorm.DetachedCriteria"},"persistentClass":{"internalPromise":{"bindErrorManager":{"bindErrorListeners":[],"class":"groovyx.gpars.dataflow.impl.DataflowChannelEventOrchestrator","listeners":[]},"bound":false,"error":false,"eventManager":{"bindErrorListeners":[],"class":"groovyx.gpars.dataflow.impl.DataflowChannelEventOrchestrator","listeners":[]}
所以有两个域名。 一个是国家地图。
class Country {
static hasMany = [regstats: Regstat]
String countryiso
String countryname
static constraints = {
countryiso size:2..2, unique: true, validator:{ it.toUpperCase() == it }
}
static mapping = {
index: 'countryiso'
}
}
和reg stat
class Regstat {
static belongsTo = [country: Country]
String reg
int status
String exturl
Date impdate
Date lupdate
String impnote
static constraints = {
reg(inList: ["FATCA", "ITC2014", "AEOI"], unique:'country')
exturl(nullable:true)
impnote(nullable:true)
impdate(nullable:true)
}
static mapping = {
index: 'reg'
impnote type: 'text'
}
}
第一次回复后更新 也尝试了
def countdata(String sn,String regsel){
def cpp = Regstat.where {
country.countryiso == sn && reg == regsel
}
render cpp as JSON
}
收到以下错误消息(以及JSON输出乱码)
| Error 2014-10-08 10:56:24,532 [http-bio-8080-exec-1] ERROR errors.GrailsExceptionResolver - NullPointerException occurred when processing request: [GET] /GenMap/getcountry/countdata - parameters:
sn: RU
regsel: FATCA
Stacktrace follows:
Message: null
Line | Method
->> 82 | <init> in groovyx.gpars.serial.SerialHandle
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 41 | <init> in ''
| 174 | <init> . . . . . . . . in groovyx.gpars.serial.SerialHandle$LocalSerialHandle
| 172 | <init> in ''
| 165 | create . . . . . . . . in groovyx.gpars.serial.SerialHandle
| 62 | getOrCreateSerialHandle in groovyx.gpars.serial.WithSerialId
| 202 | value . . . . . . . . . in grails.converters.JSON
| 162 | convertAnother in ''
| 202 | value . . . . . . . . . in ''
| 162 | convertAnother in ''
| 202 | value . . . . . . . . . in ''
| 162 | convertAnother in ''
| 202 | value . . . . . . . . . in ''
| 134 | render in ''
| 150 | render . . . . . . . . in ''
| 15 | countdata in genmap.GetcountryController$$EOs5m7Ro
| 198 | doFilter . . . . . . . in grails.plugin.cache.web.filter.PageFragmentCachingFilter
| 63 | doFilter in grails.plugin.cache.web.filter.AbstractFilter
| 1142 | runWorker . . . . . . . in java.util.concurrent.ThreadPoolExecutor
| 617 | run in java.util.concurrent.ThreadPoolExecutor$Worker
^ 745 | run . . . . . . . . . . in java.lang.Thread
答案 0 :(得分:2)
可以使用点运算符指定关联来查询关联 要查询的关联的属性名称:
这可能会奏效:
def cpp = Regstat.where {
country.countryiso == sn && reg == regsel
}
return cpp.list() as JSON
希望有所帮助