Beego中的注解路由,确实需要一些额外的步骤。具体步骤如下:
import (
"github.com/astaxie/beego"
"github.com/astaxie/beego/orm"
"github.com/astaxie/beego/validation"
"strconv"
"net/http"
"encoding/json"
"strings"
)
type MainController struct {
Beego.Controller
}
// @router / [get]
func (this *MainController) Get() {
this.TplName = "index.tpl"
}
func init() {
beego.Router("/", &controllers.MainController{})
beego.Include(&controllers.UserController{})
}
至此,我们就成功地使用了beego的注解路由。