router.go
package routers
import (
"beego01/controllers"
"github.com/astaxie/beego"
)
func init() {
beego.Router("/", &controllers.MainController{})
beego.Router("/user", &controllers.UserController{})
beego.Router("/user/add", &controllers.UserController{},"get:AddUser")
beego.Router("/user/edit", &controllers.UserController{},"get:EditUser")
}
控制器下 user.go
package controllers import ( "github.com/astaxie/beego" ) type UserController struct { beego.Controller } func (c *UserController) Get() { c.TplName = "user.tpl" } func (c *UserController) AddUser() { c.Ctx.WriteString("新增") } func (c *UserController) EditUser() { c.Ctx.WriteString("编辑") }