这个版本集成了session

 

默认session 是关闭的. 你可以如下方式来开启:

 

 

func main() {
	beego.SessionOn = true
	beego.RegisterController("/", &controllers.MainController{})
	beego.Run()
}

 

然后你就可以在控制器里面如下使用它了:

 

func (this *MainController) Get() {
	var intcount int
	sess := this.StartSession()
	count := sess.Get("count")
	beego.Info(count)
	if count == nil {
		intcount = 0
	} else {
		intcount = count.(int)
	}
	intcount = intcount + 1
	beego.Info(intcount)
	sess.Set("count", intcount)
	this.Data["Username"] = "astaxie"
	this.Data["Email"] = "astaxie@gmail.com"
	this.Data["Count"] = intcount
	this.TplNames = "index.tpl"
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-05-03
  • 2021-12-07
  • 2022-02-20
  • 2022-12-23
  • 2022-12-23
  • 2021-11-14
猜你喜欢
  • 2021-12-07
  • 2022-12-23
  • 2022-01-02
  • 2022-12-23
  • 2022-12-23
  • 2021-04-17
  • 2021-06-09
相关资源
相似解决方案