gorm 字段只映射查询,不映射写入

查询时映射结构体字段,会用到比如 select(*) as count , count并不是原表的字段,在写入数据时,count字段并不需要映射,在gorm标签内用箭头符号表示"->"。

type Model struct {
	ID            string       `gorm:"column:id;type:char(19);primaryKey;comment:id" json:"id"`                                  // id
	Name          string       `gorm:"column:name;type:varchar(64);not null;comment:名称" json:"name"`                           // 名称
	Count         int          `gorm:"column:count;->" json:"count"`                                           // 总数

}
posted @ 2025-11-13 14:29  熊先生不开玩笑  阅读(8)  评论(0)    收藏  举报