Gorm的多对多关联问题

看了别人写的框架源码,多对多关联有时候用[]A有时候用[]*A,这两个应该怎么用呢?

Authorities []SysAuthority `json:"authorities" gorm:"many2many:sys_user_authority;"`

// 另一个struct
DataAuthorityId []*SysAuthority `json:"dataAuthorityId" gorm:"many2many:sys_data_authority_id;"`

求指导,什么时候加*,它们的区别是什么

讨论数量: 1

没怎么关注,实现同等作用的代码,看心情用。 []SysAuthority 在多层调用时,内存使用应该比 []*SysAuthority 大。 虽然有一些文字有说,按值传递会比指针块,但是你看go底层的源码,大多都是用指针变量的。

1年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!