【问题标题】:Rewriting Java Controller Class with Grails REST使用 Grails REST 重写 Java 控制器类
【发布时间】:2011-09-04 20:52:02
【问题描述】:

我已经在 J​​ava 中使用 Spring 实现了一个 REST 应用程序。 GET 和 DELETE 请求示例如下:

@RequestMapping(method = RequestMethod.GET)
public
@ResponseBody
List<Configuration> getAllConfigurationsInJSON() {
    return new ArrayList<Configuration>(configurationMap.values());
}

@RequestMapping(value = "{systemId}", method = RequestMethod.DELETE)
public void deleteConfiguration(HttpServletResponse response, @PathVariable long systemId) throws IOException {
    if (configurationMap.containsKey(systemId)) {
        configurationMap.remove(systemId);
        response.setStatus(HttpServletResponse.SC_OK);
    } else {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
    }
}

我正在搜索 Grails,并想用 Grails 重写我的控制器。我读了一些文章,它表明没有必要在 Grails 上编写注释。我将只定义我的 clousers,它将呈现我对 JSON 对象的响应,就像我的 Spring 应用程序一样。如何用闭包实现它们? (我使用 IntelliJ IDEA 10.3)

【问题讨论】:

    标签: java spring grails spring-mvc groovy


    【解决方案1】:

    这段代码中没有任何东西可以使用闭包。

    在 grails 中可能看起来一样,或者您可以将 url 映射放在 UrlMappings.groovy

    【讨论】:

      猜你喜欢
      • 2013-01-23
      • 2023-04-04
      • 2020-12-21
      • 2015-07-27
      • 1970-01-01
      • 1970-01-01
      • 2014-03-18
      • 1970-01-01
      • 2015-09-07
      相关资源
      最近更新 更多