DocHub icon indicating copy to clipboard operation
DocHub copied to clipboard

咨询个问题basecontroller的问题

Open jiangjiangjiangjiangjiangjiangjiang opened this issue 7 years ago • 0 comments

在调用BaseController中的ResponseJson()函数,为什么不会抛map空指针的panic? 一般,在继承了BaseController之后,然后在调用他的ResponseJson的时候,不是会抛:Handler crashed with error assignment to entry in nil map 希望能帮忙解答下

package controllers

import ( "github.com/astaxie/beego" )

type T1Controller struct { // BaseController beego.Controller T2Controller

}

type T2Controller struct { beego.Controller }

func (this *T2Controller) Test() { data := map[string]interface{}{"status": "ok"} this.Data["json"] = data this.ServeJSON() this.StopRun() }

func (this *T1Controller) New() { re := this.GetString("status") if re == "test" { this.Test() } this.Ctx.WriteString("Hello World!") this.ServeJSON()

}