1. 路由以及url 模式
参考如下:
local lapis = require("lapis")
local app = lapis.Application() app:match("/", function(self) end) // 必须的
app:match("/hello", function(self) end)
app:match("/users/all", function(self) end)
2. 带参数的路由格式
// 包含请求参数的 使用: 

app:match("/page/:page", function(self)
print(self.params.page) // 打印输出参数, 比如 /page/dalong 输出 {page:"dalong"}
end) // 可选路由参数(使用括号)
/projects/:username(/:project) // * 符号,匹配尽可能多的参数,说白了,就是url 参数中其余的 app:match("/browse/*", function(self)
print(self.params.splat)
end)
app:match("/user/:name/file/*", function(self)
print(self.params.name, self.params.splat)
end)
3. 路由优先级
a. 完全匹配 /hello/world
b. 变量路由 /hello/:variable
c. 统配路由 /hello/*
4. 别名路由(结合self:url_for  类似路由的别名)
// 参考如下:
local lapis = require("lapis")
local app = lapis.Application() app:match("index", "/", function(self)
return self:url_for("user_profile", { name = "leaf" })
end) app:match("user_profile", "/user/:name", function(self)
return "Hello " .. self.params.name .. ", go home: " .. self:url_for("index")
end)
 
 
 
 

最新文章

  1. JUnit4使用
  2. php示例代码使用mysql_fetch_assoc函数
  3. Kruskal算法java版
  4. 关于UIWebView的总结
  5. UPC 2224 Boring Counting (离线线段树,统计区间[l,r]之间大小在[A,B]中的数的个数)
  6. jni编译non-numeric second argument to `wordlist' function错误
  7. 转:sprintf与snprintf
  8. 【6】使用nginx
  9. C++中的引用和移动语义
  10. JAVA通过I/O流复制文件
  11. 【原创】大叔经验分享(3)hbase client 如何选择
  12. redis的 rdb 和 aof 持久化的区别
  13. Pycharm 中You are using pip version 10.0.1, however version 18.1 is available. You should consider upgrading via the 'python -m pip install --upgrade pip' command.
  14. Spring 事务 readOnly 到底是怎么回事?
  15. <转>HTML、CSS、font-family:中文字体的英文名称
  16. Oracle表字段类型更改的一个经验
  17. 关于继承中的super()调用父类构造方法
  18. iOS_20_微博Dock的尾随切换
  19. 多种移动平均计算总结(MA,EMA,SMA,DMA,TMA,WMA)
  20. ASP.NET网站发布时的那些坑

热门文章

  1. 基于dapper的通用泛型分页
  2. mina-deploy(3800🌟) 快速部署工具
  3. 捕获enter键盘事件绑定到登录按钮
  4. 适配器模式(Adapter Pattern)/包装器
  5. MySQL使用RPM包方式安装
  6. mysql主从复制跳过错误
  7. JS中apply与call的用法
  8. eureka -1 - 介绍
  9. iOS系统知识架构(转)
  10. mybatis入参方式和缓冲