1

我正在编写一个 grails 应用程序。我使用 withFormat 来呈现结果。这是代码:

class TestController{
   def index(){
      def result = ["a":"1"]
      withFormat {
         json{ render result as JSON }
         xml{ render result as XML}
      }
   }
}

我使用 url.../test.../test/index.json and.../test/index 来测试它。它给了我一个HTTP Status 404错误,并告诉我the requested resource is not available. 我不确定为什么会发生这种情况。

4

1 回答 1

0

可能发生的情况是在您的 withFormat 块的任何闭包中都没有处理请求。由于您没有后备渲染,因此您将获得 404,因为可能没有 index.gsp。您应该调试该操作并了解如何处理请求。

于 2013-07-09T22:23:09.013 回答