Grails2.3.0 Rest 支持之respond和responseFormats


respond

Purpose

Attempts to return the most appropriate type for the requested content type (specified by either the Accept header or file extension)

Examples

// pick the best content type to respond with
respond Book.get(1)

// pick the best content type to respond with from the given formats respond Book.get(1), [formats:['xml', 'json']]

Description

The respond method uses Content Negotiation to respond with the most appropriate content type. See the documentation on REST support for more information.

Parameters:

  • object - The object to render
  • arguments - A map of arguments.

Supported arguments:

  • view - The view to use in case of HTML rendering
  • model - The model to use in case of HTML rendering


responseFormats

Purpose

Statically defines the supported response formats used by the respond method.

Examples

class BookController { static responseFormats = ['xml', 'json']

def show(Long id) { respond Book.get(id) } }

Description

The responseFormats property is used to define the response formats supported by a controller and in turn used by the respond method. The respond method uses Content Negotiation to respond with the most appropriate content type. See the documentation on REST support for more information.

你可能感兴趣的:(Grails2.3.0 Rest 支持之respond和responseFormats)