beego: panic: 'detail' method doesn't exist in the controller StudentController

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wangxinxinsj/article/details/88841901

beego使用报错

panic: 'detail' method doesn't exist in the controller StudentController

goroutine 1 [running]:
github.com/astaxie/beego.(*ControllerRegister).addWithMethodParams(0xc0000d8d10, 0x164d100, 0x7, 0x1736900, 0xc0000c37a0, 0x0, 0x0, 0x0, 0xc000183c08, 0x1, ...)
	/Users/wxx/go/src/github.com/astaxie/beego/router.go:179 +0x969
github.com/astaxie/beego.(*ControllerRegister).Include(0xc0000d8d10, 0xc00015aa60, 0x1, 0x1)
	/Users/wxx/go/src/github.com/astaxie/beego/router.go:286 +0x47b
github.com/astaxie/beego.(*Namespace).Include(...)
	/Users/wxx/go/src/github.com/astaxie/beego/namespace.go:186
github.com/astaxie/beego.NSInclude.func1(0xc0000bbd60)
	/Users/wxx/go/src/github.com/astaxie/beego/namespace.go:302 +0x4b
github.com/astaxie/beego.NewNamespace(0x1653cb8, 0x10, 0xc0000ac660, 0x1, 0x1, 0xc0000bbc60)
	/Users/wxx/go/src/github.com/astaxie/beego/namespace.go:42 +0x87
github.com/astaxie/beego.NSNamespace.func1(0xc0000bb920)
	/Users/wxx/go/src/github.com/astaxie/beego/namespace.go:386 +0x52
github.com/astaxie/beego.NewNamespace(0x1649c8c, 0x3, 0xc000183f48, 0x4, 0x4, 0xc000147140)
	/Users/wxx/go/src/github.com/astaxie/beego/namespace.go:42 +0x87
beego_api/routers.init.2()
	/Users/wxx/go/src/beego_api/routers/router.go:19 +0x3fb

说找不到该方法
但已经写了

// @Title 通过学生卡获取学生详情
// @Description 通过学生卡获取学生详情
// @Param	body		body 	models.User	true		"body for user content"
// @Success 200 {int} models.User.Id
// @Failure 403 body is empty
// @router /detail [get]
func (r *StudentController) detail() {

	card := r.GetString("card")
	organizationId := 22
	res := models.GetInfoByCard(card, organizationId)
	r.Data["json"] = &map[string]interface{}{"data": &res}
	r.ServeJSON()
	return
}

方法名首字母要大写,首字母要大写,首字母要大写,detail改成Detail

func (r *StudentController) Detail()

在go当中,首字母小写包内调用,如果想要包外调用需要首字母大写,go中没有private与public的概念。同一个包内的文件可以看成是一个文件,小写的话就是private,如果在不同的包内,需要首字母大写,相当于java、php中的public属性

猜你喜欢

转载自blog.csdn.net/wangxinxinsj/article/details/88841901