案例 | 参数类型 | 约定的前端变量 |
---|---|---|
respond Book.list() | java.util.List | bookList |
respond Book.get(1) | example.Book | book |
respond( [1,2] ) | java.util.List | integerList |
respond( [1,2] as Set ) | java.util.Set | integerSet |
respond( [1,2] as Integer[] ) | Integer[] | integerArray |
def show(Long id)
{
def layout = Layout.get(id)
def layoutPanel = LayoutPanel.findAllByLayout(layout, [sort: ‘displayOrder‘, order: ‘asc‘])
respond layout, model: [layoutPanel: layoutPanel] // 默认的 show 页面,传递一个对象,和一组其他对象。
}
// 选择最合适的类型并转换格式进行响应
respond Book.get(1), formats: [‘xml‘, ‘json‘]
object
需要渲染的变量,这个是必须有的!arguments
可选的参数view
- The view to use in case of HTML rendering(相应的页面)model
- The model to use in case of HTML rendering(可以相应各种类型的数据)status
- The response status(相应状态)formats
- A list of formats to respond withincludes
- Properties to include if rendering with the converters APIexcludes
- Properties to exclude if rendering with the converters APIGrails Controller - respond 方法
原文:https://www.cnblogs.com/duchaoqun/p/11834090.html