开发者

Rewriting Java Controller Class with Grails REST

开发者 https://www.devze.com 2023-04-02 15:32 出处:网络
I have implemented a REST application with Spring at Java. An example of GET and DELETE requests 开发者_运维问答are as follows:

I have implemented a REST application with Spring at Java. An example of GET and DELETE requests 开发者_运维问答are as follows:

@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);
    }
}

I am searching about Grails and want to rewrite my controller with Grails. I read some articles and it shows that there is no need to write that annotations at Grails. I will just define my clousers and it will render my response to JSON object as like my Spring applicaiton. How can I implement them with closures? (I use IntelliJ IDEA 10.3)


There is nothing in this code that can make use of closures.

In grails it may look the same, or you can put the url mappings in UrlMappings.groovy

0

精彩评论

暂无评论...
验证码 换一张
取 消