h4. Creating a controller
h4. 创建控制器(Controllers)
Controllers can be created with the [create-controller|commandLine] target. For example try running the following command from the root of a Grails project:
控制器(Controllers)可以使用[create-controller|commandLine]目标来创建.作为示例可以在Grails根目录下尝试运行下列命令。
{code:java}
grails create-controller book
{code}
The command will result in the creation of a controller at the location @grails-app/controllers/BookController.groovy@:
这条命令将导致一个控制器(Controllers)在@grails-app/controllers/BookController.groovy@位置上被创建。
{code:java}
class BookController { ... }
{code}
@BookController@ by default maps to the /book URI (relative to your application root).
@BookController@默认映射到/book URI上(相对于您的应用程序根目录)
{note}
The @create-controller@ command is merely for convenience and you can just as easily create controllers using your favorite text editor or IDE
{note}
@create-controller@命令仅仅是个方面的工具,你还可以使用你喜欢的文本编辑器或者IDE来容易的创建控制器(Controllers)。
h4. Creating Actions
h4. 创建 Actions(操作)
A controller can have multiple properties that are each assigned a block of code. Each of these properties maps to a URI:
一个控制器(Controllers)可以拥有多个属性,每个属性都被分配一个代码块.上述每个这样的属性将被映射到URI上。
{code:java}
class BookController {
def list = {
// do controller logic
// create model
return model
}
}
{code}
This example maps to the @/book/list@ URI by default thanks to the property being named @list@.
默认情况下这个例子映射到/book/list URI上,因为属性被命名为@list@。
h4. The Default Action
h4. 默认Action(操作)
A controller has the concept of a default URI that maps to the root URI of the controller. By default the default URI in this case is @/book@. The default URI is dictated by the following rules:
一个控制器(Controllers)具有默认URI的概念即映射到控制器(Controllers)的根URI。默认情况下缺省URI在这里的是@/book@。默认的URI被支配通过以下规则:
* If only one action is present the default URI for a controller maps to that action.
* 如果只有一个Action(操作)存在,一个控制器(Controllers)的默认URI将映射到该Action(操作)。
* If you define an @index@ action which is the action that handles requests when no action is specified in the URI @/book@
* 假如你定义了一个@index@ Action(操作),当没有Action(操作)被指定在URI@/book@上时,这个Action(操作)将处理请求。
* Alternatively you can set it explicitly with the @defaultAction@ property:
* 除此之外,你可以明确的设置为@defaultAction@属性:
{code:java}
def defaultAction = "list"
{code}
分享到:
相关推荐
gradle-6.1.1-all
gradle6.1.1.zip
hashcat-6.1.1 hashcat-6.1.1 hashcat-6.1.1hashcat-6.1.1hashcat-6.1.1hashcat-6.1.1
gradle-6.1.1-bin
gradle-6.1.1-all.zip
Gradle 6.1.1-all
gradle-6.1.1 zip压缩包,解决gradle官网下载缓慢的问题。直接将解压之后的zip压缩包放到对应的目录即可自动解压!
pip-6.1.1.tar.gz
gradle-6.1.1-all, 解决android studio 下载不下来问题. 下载完成后放到 C:\Users\XXX\.gradle\wrapper\dists\gradle-6.1.1-all\一串乱码文件夹中, 重启android studio 即可
gradle-6.1.1 此版这是对 6.1 的补丁版本,修复了一些 bug: 1.使用 kotlin-dsl 并使用 6.1 编译的插件与 Gradle 6.0 不兼容; 2.Gradle 6.1 发行说明中缺少已解决的问题; 3.在计算校验和时解决大型工件时的内存回...
# distributionUrl=...distributionUrl=file\:///home/george/.gradle/wrapper/dists/gradle-6.1.1-all.zip Android Studio中新建项目,gradle-6.1.1-all.zip下载太慢怎么办? - 不知道该叫什么的回答 - 知乎 ...
AKCMS是国内最著名的轻量级CMS建站程序,在主流PHP建站系统中特色鲜明,以灵活、小巧、兼容性好...AKCMS 6.1.1 更新内容:2016-06-26 1 修正了UTF8下截取内容会丢失第一个英文字符的BUG2 修正了单页上传图片报错的BUG
logstash-6.1.1.tar.gz,linux系统,官网资源,真实有效,欢迎下载
这个是kibana的6.1.1版本,可以配这es-6.1.1版本使用,下载的时候好像需要外网所以很慢,就发上来了。方便大家下载。
包括 jasperreports-6.1.1.jar jasperreports-fonts-6.1.1.jar jasperreports-javaflow-6.1.1.jar
elasticSearch 6.1.1版本,可以搭配Chrome的插件或者elasticSearch的head插件使用
Liferay6.1.1安装部署手册(Windows and Linux),Windows和Linux平台的安装部署都有,涉及mysql、oracle数据库,对初学者很有帮助