Basic Usage
- The official document: http://docs.grails.org/latest/ref/Controllers/respond.html
- And return data objects for the page where the action statement to respond to the corresponding current.
- Front and rear ends for passing object data.
- Sometimes you need to use the return statement.
- Web URL address of the client will not change.
- respond must return an "object", and then add other model and so on.
- Responds according to the content "content negotiation" automatically adapt to the type of configuration.
Case |
Parameter Type |
The front end of the agreed variable |
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']
parameter
object
Variable needs rendering, this must happen!
arguments
The optional parameter
The optional parameter
view
- The view to use in case of HTML rendering (corresponding pages)
model
- The model to use in case of HTML rendering (corresponding to various types of data may be)
status
- The response status (corresponding status)
formats
- A list of formats to respond with
includes
- Properties to include if rendering with the converters API
excludes
- Properties to exclude if rendering with the converters API