1.直接输出字符串

最后更新于:2022-04-02 04:53:27

直接输出字符串 通过beego.Controller.Ctx.WriteString()方法可以直接向http response body中输出字符串 ~~~ |-- routers | `-- router.go ~~~ ~~~ package routers import ( admin "project/admin/controllers" "github.com/astaxie/beego" ) func init() { // 固定路由也就是全匹配的路由 beego.Router("/admin/user/index", &admin.UserController{}, "*:Index") } ~~~ ~~~ |-- admin | |--controllers | `-- user.go ~~~ ~~~ package admin import ( "github.com/astaxie/beego" ) type UserController struct { beego.Controller } func (this *UserController) Index() { this.Ctx.WriteString("页面输出字符串") } ~~~ 浏览器访问: http://127.0.0.1:8080/admin/user/index 浏览器输出: ~~~ 页面输出字符串 ~~~
';