Grails中的REST跳转

Grails中自动生成的controller所实现的CRUD, 基本上是index/create/save/update/delete/show等几个方法,其中create,edit等执行后自动跳转到show, 这一跳转的关键是
8.1.5.1 Extending the RestfulController super class
 
The easiest way to get started doing so is to create a new controller for your resource that extends the grails.rest.RestfulController super class. For example:
class BookController extends RestfulController {
    static responseFormats = ['json', 'xml']
    BookController() {
        super(Book)
    }
}
To customize any logic you can just override the appropriate action. The following table provides the names of the action names and the URIs they map to:
 
HTTP MethodURIController Action
GET/booksindex
GET/books/createcreate
POST/bookssave
GET/books/${id}show
GET/books/${id}/editedit
PUT/books/${id}update
DELETE/books/${id}delete
 
update中决定跳转方向的代码是
 
request.withFormat {
            form multipartForm {
                flash.message = message(code: 'default.updated.message', args: [message(code: 'QuantityUnit.label', default: 'QuantityUnit'), quantityUnitInstance.id])
                 redirect (controller: "unitManager", action: "show", params: [id: quantityUnitInstance.id])
            }
            '*'{ redirect quantityUnitInstance, [status: OK] }
        }
下划线部分决定跳转的方向
 
自动生成的是这样的:
                redirect systemRoleInstance
为了自己的需要,被改成了上述样子——关键是改变了控制器。

你可能感兴趣的:(grails)