play framework学习笔记之 conf/routes file 路径配置文件
来源:互联网 发布:国际商务留学 知乎 编辑:程序博客网 时间:2024/04/28 04:55
例如:
GET / Application.index
就是指当 localhost:9000的时候 就会指向 Application.index 这个controller的 action method
记住 play framework是非常极端标准的MVC 和外界的交互一切都是controller在控制着view和model所以你无法直接访问 view。当然在1.2中这也不是绝对的了比如
GET /home staticFile:/public/html/index.html 就可以直接访问静态页面资源了.
package controllers;
import play.mvc.*;
public class Application extends Controller {
public static void index() {
render();
}
}
render() 就是渲染页面的方法,它会基于CoC,去找views文件夹下的Application文件夹下的index.html,
之所以有这样的CoC其实是因为
conf/routes file 路径配置文件中有这么一句
# Catch all
* /{controller}/{action} {controller}.{action}
捕获了所有的这种形式的路径
当然如果你对这样的 URL 不爽,你也可以配置 别名路径。
比如
controller里面的action方法是
public static void run(long num){
render(1);
}
则在上一个页面
<a href="@{Application.run(1)}">run</a>
我们再routes里面写到
GET /index/{num} Application.run
注意他必须在
# Catch all
* /{controller}/{action} {controller}.{action}
之前
这样我们就能生成漂亮的RESTful风格的URL了
比如 http://localhost:9000/index/1
否则会生成旧的 http://localhost:9000/application/run?num=1
在下一个页面拿数据
public static void run(long num){
String n="oo";
render(n);
}
则在页面就用
${n} 来取数据
最后发现一个现象 play的rout路径是可以不区分大小写的,都兼容
- play framework学习笔记之 conf/routes file 路径配置文件
- play framework学习笔记之 conf/routes file 路径配置文件
- Play Framework conf/routes file 路径配置文件
- play framework学习笔记之 framework ID
- java PLAY框架学习笔记--routes
- play framework学习笔记之测试test
- play framework学习笔记之yml
- play framework学习笔记之 数据库
- play framework学习笔记之 模板引擎
- play framework学习笔记之 部署项目
- play framework学习笔记之 jobs
- Play framework 路由(routes)
- play framework学习笔记之play tags页面模板
- play framework学习笔记
- Play!Framework学习笔记:初识Play
- play framework 之 配置文件的读取
- play framework学习笔记之模型域model
- play framework学习笔记之 发送 e-mail
- 类的成员函数中可以直接访问本类形参的私有变量
- Android访问WebService
- 有向图的邻接表表示法
- vc 画图控件
- 在windows下通过VC6.0第一次用C调用SQLite(转载)
- play framework学习笔记之 conf/routes file 路径配置文件
- Matlab Toolbox & Laplacian Eigenmap resources
- 收藏的经典网站
- 利用Delphi实现图像的淡入淡出
- ISO 639: Code for the Representation of the Names of Languages
- 远程连接mysql速度慢的解决方法:skip-name-resolve取消DNS的反向解析
- Delphi中TVarRec做为参数的用法
- DB2/400数据库编程
- <转>Android onTouchEvent, onClick及onLongClick的调用机制