* beego的restful路由java
https://blog.csdn.net/fareast_mzh/article/details/86667517git
* main.gogithub
// beego-route project main.go
package main
import (
"fmt"
"github.com/astaxie/beego"
)
type RegExpController struct {
beego.Controller
}
/**
* http://127.0.0.1:8081/RegExp/123
*/
func (this *RegExpController) Get() {
this.Ctx.WriteString(fmt.Sprintf("<p>In RegExp Mode</p>"))
id := this.Ctx.Input.Param(":id")
this.Ctx.WriteString(fmt.Sprintf("id is %s.<br />", id))
splat := this.Ctx.Input.Param(":splat")
this.Ctx.WriteString(fmt.Sprintf("splat is %s.<br />", splat))
path := this.Ctx.Input.Param(":path")
this.Ctx.WriteString(fmt.Sprintf("path is %s.<br />", path))
ext := this.Ctx.Input.Param(":ext")
this.Ctx.WriteString(fmt.Sprintf("ext is %s.<br />", ext))
}
func main() {
// 正則路由從path中提取參數
beego.Router("/RegExp1/?:id", &RegExpController{})
// 正則表達式匹配數字
beego.Router("/RegExp2/?:id([0-9]+)", &RegExpController{})
beego.Router("/RegExp3/?:id([\\w]+)", &RegExpController{})
// http://127.0.0.1:8081/RegExp4/abc123de (id=123)
beego.Router("/RegExp4/abc:id([0-9]+)de", &RegExpController{})
beego.Router("/RegExp5/*", &RegExpController{})
// http://127.0.0.1:8081/RegExp6/11.txt (path is 11. ext is txt.)
beego.Router("/RegExp6/*.*", &RegExpController{})
// start service
beego.Run("127.0.0.1:8081")
}
* build:
正則表達式
$ go build && ./beego-routerestful
2019/01/27 17:38:40.694 [I] http server Running on http://127.0.0.1:8081ide
* test:ui
http://127.0.0.1:8081/RegExp6/11.txtthis
https://www.imooc.com/video/18637.net
————————————————
版權聲明:本文爲CSDN博主「fareast_mzh」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處連接及本聲明。
原文連接:https://blog.csdn.net/fareast_mzh/java/article/details/86667892
3d