Grails Controller - respond 方法
基本用法
- 官方文档: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 withincludes- Properties to include if rendering with the converters APIexcludes- Properties to exclude if rendering with the converters API
Grails Controller - respond 方法的更多相关文章
- Grails Controller - redirect 方法
官方文档: http://docs.grails.org/latest/ref/Controllers/redirect.html 网页跳转方法1: // 在一个Action中直接跳转到另外一个Act ...
- 详解SpringMVC中Controller的方法中参数的工作原理[附带源码分析]
目录 前言 现象 源码分析 HandlerMethodArgumentResolver与HandlerMethodReturnValueHandler接口介绍 HandlerMethodArgumen ...
- DedeCms 5.x 本地文件包含漏洞(respond方法)
漏洞版本: DedeCms 5.x 漏洞描述: DedeCms是免费的PHP网站内容管理系统. plus/carbuyaction.php里没有对变量进行严格的过滤 出现漏洞的两个文件为: Inclu ...
- Navigation Controller 创建方法
添加Navigation Controller的方法主要有两种: 第一种:主要是通过在storyboard中拖入Object library 中的Navigation Controller 第二种方法 ...
- 【异常处理】Springboot对Controller层方法进行统一异常处理
Controller层方法,进行统一异常处理 提供两种不同的方案,如下: 方案1:使用 @@ControllerAdvice (或@RestControllerAdvice), @ExceptionH ...
- 详解SpringMVC中Controller的方法中参数的工作原理——基于maven
转自:http://www.tuicool.com/articles/F7byQn 前言 SpringMVC是目前主流的Web MVC框架之一. 如果有同学对它不熟悉,那么请参考它的入门blog:ht ...
- 【MVC - 参数原理】详解SpringMVC中Controller的方法中参数的工作原理[附带源码分析]
前言 SpringMVC是目前主流的Web MVC框架之一. 如果有同学对它不熟悉,那么请参考它的入门blog:http://www.cnblogs.com/fangjian0423/p/spring ...
- springmvc中controller内方法跳转forward?redirect?
使用springmvc的controller的时候,碰到controller内方法的跳转的问题,记录下问题以及自己测试的过程. 场景: 业务执行更新操作之后返回列表页面,列表页面需默认展示查询的列表数 ...
- springMVC中controller层方法中使用private和public问题
楼主一直习惯使用public,偶尔手误也可能使用private,但是发觉也没啥区别,都能调用service层,注入bean. 后来做一个新项目时,发觉自己以前的写的部分功能报错,当时有点懵逼,,找了半 ...
随机推荐
- Java时间格式化年-月-日-时间
Date d = new Date(); System.out.println(d); //Sat Mar 16 20:58:56 CST 2019 System.out.println(d.toLo ...
- tensorflow常用函数库
归一化函数: def norm_boxes(boxes, shape): """Converts boxes from pixel coordinates to norm ...
- JavaEE--使用百度echarts实现地图报表
参考:http://echarts.baidu.com/option.html#title https://www.cnblogs.com/zhangyong123/p/4974554.html ht ...
- openv uMat和Mat数据格式的转换
Mat 转成 UMat: UMat umat; mat.copyTo(umat); UMat转成 Mat : Mat mat; umat.copyTo(mat);
- SeetaFaceEngine系列2:Face Alignment编译和使用
前面一篇写了编译人脸检测部分,现在就介绍下人脸配准部分,SeetaFace的Face Alignment通过人脸的五个关键点来配准人脸,也就是双眼.鼻尖.两个嘴角. 这部分的编译也和上一篇一样,步骤如 ...
- h5-钟表动画案例
1.html代码 <div class="clock"> <div class="line line1"> <div class= ...
- 对接memcache经验分享
接口访问日志 数据结构 分享 apiname 接口名称 apiname[cnt]接口访问次数每访问一次增加一次 这里要处理并发问题 我还没有解决: apiname[cnt][n][spent_tim ...
- slideshare文档下载
if [ x"$1" = x1 ]; then for i in {1..46}; do url_i="https://image.slidesharecdn.com/b ...
- P1781 宇宙总统
题目地址:https://www.luogu.com.cn/problem/P1781 题目描述:地球历公元 6036 年,全宇宙准备竞选一个最贤能的人当总统,共有 n 个非凡拔尖的人竞选总统,现在票 ...
- Java的各类型数据在内存中分配情况详解
1. 有这样一种说法,如今争锋于IT战场的两大势力,MS一族偏重于底层实现,Java一族偏重于系统架构.说法根据无从考证,但从两大势力各自的社区力量和图书市场已有佳作不难看出,此说法不虚,但 ...