首页 > 其他 > 详细

Grails Controller - respond 方法

时间:2019-11-11 13:04:37      阅读:146      评论:0      收藏:0      [点我收藏+]

基本用法

  • 官方文档: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

Grails Controller - respond 方法

原文:https://www.cnblogs.com/duchaoqun/p/11834090.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!