可由其他项(如id)访问的rest服务

可由其他项(如id)访问的rest服务,rest,grails,Rest,Grails,我通过公开一个简单的域类来运行restservice。我可以通过 http://localhost:8080/Bic/bic/17.json 我得到: {“类”:“org.strotmann.bic.BankIdentCode”,“id”:17,“bankname”:“ABK Kreditbank”,“bic”:“ABKBDEB1XXX”,“blz”:10030400,“ort”:“Berlin”,“plz”:10115} 我想通过blz=10030400或域类的任何其他项(id除外)进行访问

我通过公开一个简单的域类来运行restservice。我可以通过

http://localhost:8080/Bic/bic/17.json
我得到:

{“类”:“org.strotmann.bic.BankIdentCode”,“id”:17,“bankname”:“ABK Kreditbank”,“bic”:“ABKBDEB1XXX”,“blz”:10030400,“ort”:“Berlin”,“plz”:10115}

我想通过blz=10030400或域类的任何其他项(id除外)进行访问

怎么做

彼得
德国多特蒙德

控制器操作代码(您应该在此处发布!)可以如下所示:

def bic(){
  def entry = params.find{ k, v -> Bic.metaClass.hasMetaProperty k }
  if( entry ) 
    render( Bic.withCriteria( uniqueResult:true ){ eq entry.key, entry.value } as JSON )
  else
    render text:'not found!`
}

package org.strotmann.bic import grails.rest.*import org.codehaus.groovy.grails.web.json.json对象类BankIdentitCodeController扩展RestfulController{static responseFormats=['json',xml']BankIdentitCodeController(){super(BankIdentitCode)}def bic(){def entry=params.find{k,v->bic.metaClass.hasMetaProperty k}if(entry)render(Bic.withCriteria(uniqueResult:true){eq entry.key,entry.value}作为JSONObject)else render text:'notfound!'}
抱歉,我不知道如何格式化。使用obove控制器代码并在浏览器中输入所请求的资源不可用。您应该输入
localhost:8080/bankIdentCode/bic?bic=333
如果您使用默认url映射,感谢您,到目前为止,除了JSON格式外,它现在工作正常。编译器不接受as JSON子句(没有类JSON),请告诉我要导入哪个包。我尝试了org.codehaus.groovy.grails.web.json包中的JSONObject,但这也不起作用。