1曹动、 router.go 中設置正則路由
func init() {
beego.Router("/article/?:id", &api.ArticleController{})
}
默認匹配 //例如對于URL”/article/123”可以匹配成功牲览,此時變量”:id”值為”123”
2墓陈、controllers 中獲取id
type ArticleController struct {
beego.Controller
}
// 獲取單個文章
func (this *ArticleController) Get() {
id := this.Ctx.Input.Param(":id")
log.Println(id)
}
調(diào)用this.Ctx.Input.Param()即可獲取對應值
3、注意:beego默認開啟模板解析
beego默認會開啟模板解析熬的,如果不關閉就會像這樣:
在app.conf文件內(nèi)添加上語句:autorender = false赊级,此時得到了我們想要的結果岔绸。