Grails控制器类错误

Grails控制器类错误,grails,model-view-controller,web,web-applications,Grails,Model View Controller,Web,Web Applications,我正在对此控制器类中的函数进行API调用: class CountryInfoController extends RestfulController { static responseformats = ['json'] CountryInfoController(){ super(CountryInfo) } def index(){} def getCountryName(){ System.out.println('all good') } } 但是,它给了我一个

我正在对此控制器类中的函数进行API调用:

class CountryInfoController extends RestfulController {
static responseformats = ['json']

CountryInfoController(){
    super(CountryInfo)
}

def index(){}

def getCountryName(){
    System.out.println('all good')
}
}

但是,它给了我一个错误500:内部服务器错误


我不确定我是否错过了一个视图或其他东西——我是Grails的新手,所以我很困惑到底发生了什么。任何想法都将不胜感激!谢谢

控制器希望渲染某些内容。 如果未指定返回数据,请使用: 返回响应渲染, grails将尝试在视图文件夹中查找与方法同名的视图。
Grails文档:

控制器希望渲染一些东西。 如果未指定返回数据,请使用: 返回响应渲染, grails将尝试在视图文件夹中查找与方法同名的视图。
Grails文档:

与Evgeny提到的一样,控制器试图重定向到一个不存在的视图。我假设您希望使用JSON响应—如果是这样,您可以使用域对象响应

def getCountryName(){
    def c_info = CountryInfo.find(params.name)
    if(c_info != null)
        respond c_info
    // Otherwise, return error status
    response.status = 404
}

就像Evgeny提到的,控制器试图重定向到一个不存在的视图。我假设您希望使用JSON响应—如果是这样,您可以使用域对象响应

def getCountryName(){
    def c_info = CountryInfo.find(params.name)
    if(c_info != null)
        respond c_info
    // Otherwise, return error status
    response.status = 404
}