首页  

play HTTP routing     所属分类 play 浏览量 668
https://www.playframework.com/documentation/2.8.x/ScalaRouting

The built-in HTTP router

The router is the component in charge of translating each incoming HTTP request to an Action.


An HTTP request is seen as an event by the MVC framework.  
http请求 事件

the request path  , including the query string
the HTTP method 

路由配置文件 conf/routes 
会编译生成   Routes
路由错误会在浏览器直接显示

Play’s default routes generator creates a router class that accepts controller instances in an @Inject-annotated constructor.
Play的默认路由生成器创建了一个路由器类,它接受@inject注释的构造函数中的控制器实例

GET    /hello   controllers.HomeController.hello
GET   /clients/:id          controllers.Clients.show(id: Long)
GET   /clients/all          controllers.Clients.list()
+ nocsrf
POST  /api/new              controllers.Api.newThing


The HTTP method
GET, PATCH, POST, PUT, DELETE, HEAD


Parameter types 支持的类型 String Int Long Double Float Boolean UUID AnyVal wrappers for other supported types Parameters with fixed values GET / controllers.Application.show(page = "home") GET /:page controllers.Application.show(page) Parameters with default values # Pagination links, like /clients?page=3 GET /clients controllers.Clients.list(page: Int ?= 1) List parameters # E.g. /api/list-items?item=red&item=new&item=slippers GET /api/list-items controllers.Api.listItems(item: List[String]) # or # E.g. /api/list-int-items?item=1&item=42 GET /api/list-int-items controllers.Api.listIntItems(item: List[Int])
Routing priority Many routes can match the same request. If there is a conflict, the first route (in declaration order) is used.
The Default Controller GET /about controllers.Default.redirect(to = "https://codefun007.xyz/") GET /orders controllers.Default.notFound # Responds with 500 Internal Server Error GET /clients controllers.Default.error # Responds with 501 Not Implemented GET /posts controllers.Default.todo Play provides a DSL for defining embedded routers called the String Interpolating Routing DSL, or SIRD for short

上一篇     下一篇
scala 包对象 package object

play Configuration 配置读取

play action 要点

play框架日志

play框架依赖注入

play 数据库访问