更改grails资源默认操作名称/标签

时间:2016-06-24 21:57:24

标签: grails

当我们使用资源属性来定义像" / api / user"(资源:'用户')这样的映射时,Grails会创建以下映射:

"/api/user/create"(controller: 'user', action: 'create', method: 'GET')
"/api/user/edit"(controller: 'user', action: 'edit', method: 'GET')
"/api/user(.(*))?"(controller: 'user', action: 'delete', method: 'DELETE')
"/api/user(.(*))?"(controller: 'user', action: 'update', method: 'PUT')
"/api/user(.(*))?"(controller: 'user', action: 'save', method: 'POST')

好吧,我想要做的就是更改这些默认值,以便我可以将操作转换为我的母语。因此,当我创建资源时,我希望这些操作是:" criar,editar,deletar,atualizar,salvar"。

这可能吗?我怎么能做到这一点?

提前致谢。

1 个答案:

答案 0 :(得分:1)

您应该编写一个新的RestfulController实现(基于@Resource AST(抽象语法树)注释,我们可以将其用作superClass)。

检查出来:http://mrhaki.blogspot.com/2014/07/grails-goodness-custom-controller-class.html

基于RestfulController实现: https://github.com/grails/grails-core/blob/master/grails-plugin-rest/src/main/groovy/grails/rest/RestfulController.groovy