自动路由下的urlfor

URL构建与控制器关系(路由绑定)

beego.UrlFor函数返回控制器方法所返回的url

  1. router => url controller
  2. AutoRouter => controller => URL(controller/action)
  3. controller.Action => url
  4. beego.UrlFor => Controller.Redirect => URL =>beego.UrlFor=>template a.href/form.action => URL=> urlfor

在控制器中

  1. c.Redirect("/user/query",302) //跳转可以使用urlfor
  2. // fmt.Println(beego.URLFor("UserController.Query"))
  3. // 使用urlfor c.Redirect(beego.URLFor("UserController.Query"),302)
  4. return

在模板中

  1. <a class="nav-link" href="{{ urlfor `UserController.Query` }}">模板中使用urlfor</a>
文档更新时间: 2023-08-08 18:47   作者:张尚