基本用法

  • 官方文档:http://docs.grails.org/latest/ref/Controllers/respond.html
  • 为当前 respond 语句所在 action 所对应的页面返回数据和对象。
  • 适合前后端传递对象数据。
  • 有的时候需要使用 return 语句。
  • 客户端的网页URL地址不会改变。
  • respond 必须返回一个“对象”,然后加上其他的model等。
  • 根据“内容协商”配置的内容进行响应自动适应类型。
案例 参数类型 约定的前端变量
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 with
  • includes - Properties to include if rendering with the converters API
  • excludes - Properties to exclude if rendering with the converters API

最新文章

  1. C#基础,C#基础知识点,基础知识点迅速巩固
  2. 初学js
  3. spring mvc 拦截器 拦截子目录
  4. STL函数模板(即算法)一览
  5. mysql之存储引擎
  6. 达内TTS6.0课件oop_day04
  7. 【原创】重绘winform的GroupBox
  8. HBase的Snapshots功能介绍
  9. Vue-computed的set和get
  10. Source map error
  11. 聊聊大麦网UWP版的首页顶部图片联动效果的实现方法
  12. TRIO-basic指令--九九乘法表demo
  13. Codeforces 698A - Vacations - [简单DP]
  14. PADS Logic Ref Des Start Value
  15. 客户端负载均衡Feign之二:Feign 功能介绍
  16. leetcode1017
  17. byte类型的127+1=-128?
  18. 第3章:Hadoop分布式文件系统(2)
  19. Windows Server 2008 R2之管理Sysvol文件夹
  20. extern "C" 的用意

热门文章

  1. Vue.js(4)- 生命周期
  2. 【Python】关于import QtCore报错的处理方法
  3. Django2.0模型基础——(一)
  4. JZOJ-TG817-A-solution
  5. android studio 修改新建EmptyActivity默认布局
  6. Python dict 和 list 转换
  7. 前端快速构建神器vue-cli,windows下安装并且构建前端项目
  8. 阿里云Linux格式化数据盘,分区并挂载一个文件系统
  9. 发布订阅--DBMS "无法作为数据库主体执行,因为主体“dbo”不存在、无法模拟这种..........”
  10. 14 微服务电商【黑马乐优商城】:day04-ES6语法入门