问题描述
我开始寻找Grails的JAX-RS插件,并认为这主要是因为它基于JSR-311,我认为遵循标准通常是 做。然而,使用Grail的UrlMappings,我似乎基本上达到了同样的效果。我想我错过了一些东西,但是,我们没有做任何过于复杂的事情。我们基本上只需要通过API公开CRUD。这两个版本都做同样的事情:
JAX-RS:
<$ c
@Consumes(['application / json'])
@Produces(['application / json'])
响应putUser(用户用户){
user.save(flush:true)
ok用户
}
Grails:
def update = {
def user = new User(params ['user'])
user .save(flush:true)
将用户显示为JSON
}
显然,这是一个过分简化的例子,就像我说的,也许我错过了一些重要的东西。另外,关于Grails构建机制的好处是我可以利用内容协商。
任何人对此有任何意见?
$ b $我不得不作出同样的决定,并且我发现使用URL映射更容易,因为API不那么复杂,并且数量有限需要支持的API调用。如果归结到基于LOE和可支持实现的资源更容易维护。
I started out looking at the JAX-RS plugin for grails and thought that was the way to go mainly because it was based on JSR-311 and I figure following standards is usually the smart thing to do. However, using Grail's UrlMappings it seems I basically achieve the same thing. I figure I'm missing something, however, we aren't doing anything overly complex. We basically just need to expose CRUD via an API. Example of doing the same thing with both versions:
JAX-RS:
@PUT
@Consumes(['application/json'])
@Produces(['application/json'])
Response putUser(User user) {
user.save(flush:true)
ok user
}
Grails:
def update = {
def user = new User(params['user'])
user.save(flush:true)
render user as JSON
}
Obviously, this is an overly-simplified example and like I said, maybe I'm missing something important. Also, the nice thing about the Grails built in mechanism is I can utilize Content Negotiation along with it.
Anyone have any opinions on this?
I had to make the same decision, and I found it just easier to use URL Mappings because the API was not that complex and there were a limited number of API calls that needed to supported.
If came down to what would be easier to maintain based on the LOE and the resources able to support the implementation.
这篇关于Grails使用JAX-RS和UrlMappings进行RESTful服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!