什么情况下用指针,什么情况下用对象?
1. 运行环境
当前使用的Go版本: go 1.23.5
2. 问题描述?
model user 中,Link 方法的关联定义是指针 user *User 就导致 go 模板中,不能调用方法,调取属性了,但是只在 show.gohtml 页面执行失败, index.gohtml 的时候执行成功
app/models/user/user.go
.
.
.
// 注意:教程上面是 user User <==
func (user *User) Link() string {
return route.Name2URL("users.show", "id", user.GetStringID())
}
3. 您期望得到的结果?

4. 您实际得到的结果?
index.gohtml 就是符合预期

show.gohtml 的就很尴尬


以下是报错信息

关于 LearnKu
推荐文章: